annotate libgomp/env.c @ 121:49957f95a4d1

fix fntype
author anatofuz
date Fri, 09 Mar 2018 19:18:14 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents: 67
diff changeset
1 /* Copyright (C) 2005-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 Contributed by Richard Henderson <rth@redhat.com>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
111
kono
parents: 67
diff changeset
4 This file is part of the GNU Offloading and Multi Processing Library
kono
parents: 67
diff changeset
5 (libgomp).
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 Libgomp is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
111
kono
parents: 67
diff changeset
26 /* This file defines the OpenMP internal control variables and arranges
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 for them to be initialized from environment variables at startup. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
111
kono
parents: 67
diff changeset
29 #define _GNU_SOURCE
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #include "libgomp.h"
111
kono
parents: 67
diff changeset
31 #include "gomp-constants.h"
kono
parents: 67
diff changeset
32 #include <limits.h>
kono
parents: 67
diff changeset
33 #ifndef LIBGOMP_OFFLOADED_ONLY
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 #include "libgomp_f.h"
111
kono
parents: 67
diff changeset
35 #include "oacc-int.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 #include <ctype.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 #include <stdlib.h>
111
kono
parents: 67
diff changeset
38 #include <stdio.h>
kono
parents: 67
diff changeset
39 #ifdef HAVE_INTTYPES_H
kono
parents: 67
diff changeset
40 # include <inttypes.h> /* For PRIu64. */
kono
parents: 67
diff changeset
41 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #ifdef STRING_WITH_STRINGS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 # include <string.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 # include <strings.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 # ifdef HAVE_STRING_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 # include <string.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 # else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 # ifdef HAVE_STRINGS_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 # include <strings.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 # endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 #include <errno.h>
111
kono
parents: 67
diff changeset
55 #include "thread-stacksize.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 #ifndef HAVE_STRTOULL
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 # define strtoull(ptr, eptr, base) strtoul (ptr, eptr, base)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 #endif
111
kono
parents: 67
diff changeset
60 #endif /* LIBGOMP_OFFLOADED_ONLY */
kono
parents: 67
diff changeset
61
kono
parents: 67
diff changeset
62 #include "secure_getenv.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 struct gomp_task_icv gomp_global_icv = {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 .nthreads_var = 1,
111
kono
parents: 67
diff changeset
66 .thread_limit_var = UINT_MAX,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 .run_sched_var = GFS_DYNAMIC,
111
kono
parents: 67
diff changeset
68 .run_sched_chunk_size = 1,
kono
parents: 67
diff changeset
69 .default_device_var = 0,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 .dyn_var = false,
111
kono
parents: 67
diff changeset
71 .nest_var = false,
kono
parents: 67
diff changeset
72 .bind_var = omp_proc_bind_false,
kono
parents: 67
diff changeset
73 .target_data = NULL
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 unsigned long gomp_max_active_levels_var = INT_MAX;
111
kono
parents: 67
diff changeset
77 bool gomp_cancel_var = false;
kono
parents: 67
diff changeset
78 int gomp_max_task_priority_var = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 #ifndef HAVE_SYNC_BUILTINS
111
kono
parents: 67
diff changeset
80 gomp_mutex_t gomp_managed_threads_lock;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 unsigned long gomp_available_cpus = 1, gomp_managed_threads = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 unsigned long long gomp_spin_count_var, gomp_throttled_spin_count_var;
111
kono
parents: 67
diff changeset
84 unsigned long *gomp_nthreads_var_list, gomp_nthreads_var_list_len;
kono
parents: 67
diff changeset
85 char *gomp_bind_var_list;
kono
parents: 67
diff changeset
86 unsigned long gomp_bind_var_list_len;
kono
parents: 67
diff changeset
87 void **gomp_places_list;
kono
parents: 67
diff changeset
88 unsigned long gomp_places_list_len;
kono
parents: 67
diff changeset
89 int gomp_debug_var;
kono
parents: 67
diff changeset
90 unsigned int gomp_num_teams_var;
kono
parents: 67
diff changeset
91 char *goacc_device_type;
kono
parents: 67
diff changeset
92 int goacc_device_num;
kono
parents: 67
diff changeset
93
kono
parents: 67
diff changeset
94 #ifndef LIBGOMP_OFFLOADED_ONLY
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 /* Parse the OMP_SCHEDULE environment variable. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 parse_schedule (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 char *env, *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 unsigned long value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 env = getenv ("OMP_SCHEDULE");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 if (env == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 if (strncasecmp (env, "static", 6) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 gomp_global_icv.run_sched_var = GFS_STATIC;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 env += 6;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 else if (strncasecmp (env, "dynamic", 7) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 gomp_global_icv.run_sched_var = GFS_DYNAMIC;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 env += 7;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 else if (strncasecmp (env, "guided", 6) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 gomp_global_icv.run_sched_var = GFS_GUIDED;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 env += 6;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 else if (strncasecmp (env, "auto", 4) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 gomp_global_icv.run_sched_var = GFS_AUTO;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 env += 4;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 goto unknown;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 if (*env == '\0')
111
kono
parents: 67
diff changeset
136 {
kono
parents: 67
diff changeset
137 gomp_global_icv.run_sched_chunk_size
kono
parents: 67
diff changeset
138 = gomp_global_icv.run_sched_var != GFS_STATIC;
kono
parents: 67
diff changeset
139 return;
kono
parents: 67
diff changeset
140 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 if (*env++ != ',')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 goto unknown;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 if (*env == '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 errno = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 value = strtoul (env, &end, 10);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 if (errno)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 while (isspace ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 if (*end != '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 if ((int)value != value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
111
kono
parents: 67
diff changeset
161 if (value == 0 && gomp_global_icv.run_sched_var != GFS_STATIC)
kono
parents: 67
diff changeset
162 value = 1;
kono
parents: 67
diff changeset
163 gomp_global_icv.run_sched_chunk_size = value;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 unknown:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 gomp_error ("Unknown value for environment variable OMP_SCHEDULE");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 invalid:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 gomp_error ("Invalid value for chunk size in "
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 "environment variable OMP_SCHEDULE");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 /* Parse an unsigned long environment variable. Return true if one was
111
kono
parents: 67
diff changeset
177 present and it was successfully parsed. If SECURE, use secure_getenv to the
kono
parents: 67
diff changeset
178 environment variable. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 static bool
111
kono
parents: 67
diff changeset
181 parse_unsigned_long_1 (const char *name, unsigned long *pvalue, bool allow_zero,
kono
parents: 67
diff changeset
182 bool secure)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 char *env, *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 unsigned long value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186
111
kono
parents: 67
diff changeset
187 env = (secure ? secure_getenv (name) : getenv (name));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 if (env == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 if (*env == '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 errno = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 value = strtoul (env, &end, 10);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
198 if (errno || (long) value <= 0 - allow_zero)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 while (isspace ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 if (*end != '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 *pvalue = value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 invalid:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 gomp_error ("Invalid value for environment variable %s", name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
111
kono
parents: 67
diff changeset
214 /* As parse_unsigned_long_1, but always use getenv. */
kono
parents: 67
diff changeset
215
kono
parents: 67
diff changeset
216 static bool
kono
parents: 67
diff changeset
217 parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
kono
parents: 67
diff changeset
218 {
kono
parents: 67
diff changeset
219 return parse_unsigned_long_1 (name, pvalue, allow_zero, false);
kono
parents: 67
diff changeset
220 }
kono
parents: 67
diff changeset
221
kono
parents: 67
diff changeset
222 /* Parse a positive int environment variable. Return true if one was
kono
parents: 67
diff changeset
223 present and it was successfully parsed. If SECURE, use secure_getenv to the
kono
parents: 67
diff changeset
224 environment variable. */
kono
parents: 67
diff changeset
225
kono
parents: 67
diff changeset
226 static bool
kono
parents: 67
diff changeset
227 parse_int_1 (const char *name, int *pvalue, bool allow_zero, bool secure)
kono
parents: 67
diff changeset
228 {
kono
parents: 67
diff changeset
229 unsigned long value;
kono
parents: 67
diff changeset
230 if (!parse_unsigned_long_1 (name, &value, allow_zero, secure))
kono
parents: 67
diff changeset
231 return false;
kono
parents: 67
diff changeset
232 if (value > INT_MAX)
kono
parents: 67
diff changeset
233 {
kono
parents: 67
diff changeset
234 gomp_error ("Invalid value for environment variable %s", name);
kono
parents: 67
diff changeset
235 return false;
kono
parents: 67
diff changeset
236 }
kono
parents: 67
diff changeset
237 *pvalue = (int) value;
kono
parents: 67
diff changeset
238 return true;
kono
parents: 67
diff changeset
239 }
kono
parents: 67
diff changeset
240
kono
parents: 67
diff changeset
241 /* As parse_int_1, but use getenv. */
kono
parents: 67
diff changeset
242
kono
parents: 67
diff changeset
243 static bool
kono
parents: 67
diff changeset
244 parse_int (const char *name, int *pvalue, bool allow_zero)
kono
parents: 67
diff changeset
245 {
kono
parents: 67
diff changeset
246 return parse_int_1 (name, pvalue, allow_zero, false);
kono
parents: 67
diff changeset
247 }
kono
parents: 67
diff changeset
248
kono
parents: 67
diff changeset
249 /* As parse_int_1, but use getenv_secure. */
kono
parents: 67
diff changeset
250
kono
parents: 67
diff changeset
251 static bool
kono
parents: 67
diff changeset
252 parse_int_secure (const char *name, int *pvalue, bool allow_zero)
kono
parents: 67
diff changeset
253 {
kono
parents: 67
diff changeset
254 return parse_int_1 (name, pvalue, allow_zero, true);
kono
parents: 67
diff changeset
255 }
kono
parents: 67
diff changeset
256
kono
parents: 67
diff changeset
257 /* Parse an unsigned long list environment variable. Return true if one was
kono
parents: 67
diff changeset
258 present and it was successfully parsed. */
kono
parents: 67
diff changeset
259
kono
parents: 67
diff changeset
260 static bool
kono
parents: 67
diff changeset
261 parse_unsigned_long_list (const char *name, unsigned long *p1stvalue,
kono
parents: 67
diff changeset
262 unsigned long **pvalues,
kono
parents: 67
diff changeset
263 unsigned long *pnvalues)
kono
parents: 67
diff changeset
264 {
kono
parents: 67
diff changeset
265 char *env, *end;
kono
parents: 67
diff changeset
266 unsigned long value, *values = NULL;
kono
parents: 67
diff changeset
267
kono
parents: 67
diff changeset
268 env = getenv (name);
kono
parents: 67
diff changeset
269 if (env == NULL)
kono
parents: 67
diff changeset
270 return false;
kono
parents: 67
diff changeset
271
kono
parents: 67
diff changeset
272 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
273 ++env;
kono
parents: 67
diff changeset
274 if (*env == '\0')
kono
parents: 67
diff changeset
275 goto invalid;
kono
parents: 67
diff changeset
276
kono
parents: 67
diff changeset
277 errno = 0;
kono
parents: 67
diff changeset
278 value = strtoul (env, &end, 10);
kono
parents: 67
diff changeset
279 if (errno || (long) value <= 0)
kono
parents: 67
diff changeset
280 goto invalid;
kono
parents: 67
diff changeset
281
kono
parents: 67
diff changeset
282 while (isspace ((unsigned char) *end))
kono
parents: 67
diff changeset
283 ++end;
kono
parents: 67
diff changeset
284 if (*end != '\0')
kono
parents: 67
diff changeset
285 {
kono
parents: 67
diff changeset
286 if (*end == ',')
kono
parents: 67
diff changeset
287 {
kono
parents: 67
diff changeset
288 unsigned long nvalues = 0, nalloced = 0;
kono
parents: 67
diff changeset
289
kono
parents: 67
diff changeset
290 do
kono
parents: 67
diff changeset
291 {
kono
parents: 67
diff changeset
292 env = end + 1;
kono
parents: 67
diff changeset
293 if (nvalues == nalloced)
kono
parents: 67
diff changeset
294 {
kono
parents: 67
diff changeset
295 unsigned long *n;
kono
parents: 67
diff changeset
296 nalloced = nalloced ? nalloced * 2 : 16;
kono
parents: 67
diff changeset
297 n = realloc (values, nalloced * sizeof (unsigned long));
kono
parents: 67
diff changeset
298 if (n == NULL)
kono
parents: 67
diff changeset
299 {
kono
parents: 67
diff changeset
300 free (values);
kono
parents: 67
diff changeset
301 gomp_error ("Out of memory while trying to parse"
kono
parents: 67
diff changeset
302 " environment variable %s", name);
kono
parents: 67
diff changeset
303 return false;
kono
parents: 67
diff changeset
304 }
kono
parents: 67
diff changeset
305 values = n;
kono
parents: 67
diff changeset
306 if (nvalues == 0)
kono
parents: 67
diff changeset
307 values[nvalues++] = value;
kono
parents: 67
diff changeset
308 }
kono
parents: 67
diff changeset
309
kono
parents: 67
diff changeset
310 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
311 ++env;
kono
parents: 67
diff changeset
312 if (*env == '\0')
kono
parents: 67
diff changeset
313 goto invalid;
kono
parents: 67
diff changeset
314
kono
parents: 67
diff changeset
315 errno = 0;
kono
parents: 67
diff changeset
316 value = strtoul (env, &end, 10);
kono
parents: 67
diff changeset
317 if (errno || (long) value <= 0)
kono
parents: 67
diff changeset
318 goto invalid;
kono
parents: 67
diff changeset
319
kono
parents: 67
diff changeset
320 values[nvalues++] = value;
kono
parents: 67
diff changeset
321 while (isspace ((unsigned char) *end))
kono
parents: 67
diff changeset
322 ++end;
kono
parents: 67
diff changeset
323 if (*end == '\0')
kono
parents: 67
diff changeset
324 break;
kono
parents: 67
diff changeset
325 if (*end != ',')
kono
parents: 67
diff changeset
326 goto invalid;
kono
parents: 67
diff changeset
327 }
kono
parents: 67
diff changeset
328 while (1);
kono
parents: 67
diff changeset
329 *p1stvalue = values[0];
kono
parents: 67
diff changeset
330 *pvalues = values;
kono
parents: 67
diff changeset
331 *pnvalues = nvalues;
kono
parents: 67
diff changeset
332 return true;
kono
parents: 67
diff changeset
333 }
kono
parents: 67
diff changeset
334 goto invalid;
kono
parents: 67
diff changeset
335 }
kono
parents: 67
diff changeset
336
kono
parents: 67
diff changeset
337 *p1stvalue = value;
kono
parents: 67
diff changeset
338 return true;
kono
parents: 67
diff changeset
339
kono
parents: 67
diff changeset
340 invalid:
kono
parents: 67
diff changeset
341 free (values);
kono
parents: 67
diff changeset
342 gomp_error ("Invalid value for environment variable %s", name);
kono
parents: 67
diff changeset
343 return false;
kono
parents: 67
diff changeset
344 }
kono
parents: 67
diff changeset
345
kono
parents: 67
diff changeset
346 /* Parse environment variable set to a boolean or list of omp_proc_bind_t
kono
parents: 67
diff changeset
347 enum values. Return true if one was present and it was successfully
kono
parents: 67
diff changeset
348 parsed. */
kono
parents: 67
diff changeset
349
kono
parents: 67
diff changeset
350 static bool
kono
parents: 67
diff changeset
351 parse_bind_var (const char *name, char *p1stvalue,
kono
parents: 67
diff changeset
352 char **pvalues, unsigned long *pnvalues)
kono
parents: 67
diff changeset
353 {
kono
parents: 67
diff changeset
354 char *env;
kono
parents: 67
diff changeset
355 char value = omp_proc_bind_false, *values = NULL;
kono
parents: 67
diff changeset
356 int i;
kono
parents: 67
diff changeset
357 static struct proc_bind_kinds
kono
parents: 67
diff changeset
358 {
kono
parents: 67
diff changeset
359 const char name[7];
kono
parents: 67
diff changeset
360 const char len;
kono
parents: 67
diff changeset
361 omp_proc_bind_t kind;
kono
parents: 67
diff changeset
362 } kinds[] =
kono
parents: 67
diff changeset
363 {
kono
parents: 67
diff changeset
364 { "false", 5, omp_proc_bind_false },
kono
parents: 67
diff changeset
365 { "true", 4, omp_proc_bind_true },
kono
parents: 67
diff changeset
366 { "master", 6, omp_proc_bind_master },
kono
parents: 67
diff changeset
367 { "close", 5, omp_proc_bind_close },
kono
parents: 67
diff changeset
368 { "spread", 6, omp_proc_bind_spread }
kono
parents: 67
diff changeset
369 };
kono
parents: 67
diff changeset
370
kono
parents: 67
diff changeset
371 env = getenv (name);
kono
parents: 67
diff changeset
372 if (env == NULL)
kono
parents: 67
diff changeset
373 return false;
kono
parents: 67
diff changeset
374
kono
parents: 67
diff changeset
375 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
376 ++env;
kono
parents: 67
diff changeset
377 if (*env == '\0')
kono
parents: 67
diff changeset
378 goto invalid;
kono
parents: 67
diff changeset
379
kono
parents: 67
diff changeset
380 for (i = 0; i < 5; i++)
kono
parents: 67
diff changeset
381 if (strncasecmp (env, kinds[i].name, kinds[i].len) == 0)
kono
parents: 67
diff changeset
382 {
kono
parents: 67
diff changeset
383 value = kinds[i].kind;
kono
parents: 67
diff changeset
384 env += kinds[i].len;
kono
parents: 67
diff changeset
385 break;
kono
parents: 67
diff changeset
386 }
kono
parents: 67
diff changeset
387 if (i == 5)
kono
parents: 67
diff changeset
388 goto invalid;
kono
parents: 67
diff changeset
389
kono
parents: 67
diff changeset
390 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
391 ++env;
kono
parents: 67
diff changeset
392 if (*env != '\0')
kono
parents: 67
diff changeset
393 {
kono
parents: 67
diff changeset
394 if (*env == ',')
kono
parents: 67
diff changeset
395 {
kono
parents: 67
diff changeset
396 unsigned long nvalues = 0, nalloced = 0;
kono
parents: 67
diff changeset
397
kono
parents: 67
diff changeset
398 if (value == omp_proc_bind_false
kono
parents: 67
diff changeset
399 || value == omp_proc_bind_true)
kono
parents: 67
diff changeset
400 goto invalid;
kono
parents: 67
diff changeset
401
kono
parents: 67
diff changeset
402 do
kono
parents: 67
diff changeset
403 {
kono
parents: 67
diff changeset
404 env++;
kono
parents: 67
diff changeset
405 if (nvalues == nalloced)
kono
parents: 67
diff changeset
406 {
kono
parents: 67
diff changeset
407 char *n;
kono
parents: 67
diff changeset
408 nalloced = nalloced ? nalloced * 2 : 16;
kono
parents: 67
diff changeset
409 n = realloc (values, nalloced);
kono
parents: 67
diff changeset
410 if (n == NULL)
kono
parents: 67
diff changeset
411 {
kono
parents: 67
diff changeset
412 free (values);
kono
parents: 67
diff changeset
413 gomp_error ("Out of memory while trying to parse"
kono
parents: 67
diff changeset
414 " environment variable %s", name);
kono
parents: 67
diff changeset
415 return false;
kono
parents: 67
diff changeset
416 }
kono
parents: 67
diff changeset
417 values = n;
kono
parents: 67
diff changeset
418 if (nvalues == 0)
kono
parents: 67
diff changeset
419 values[nvalues++] = value;
kono
parents: 67
diff changeset
420 }
kono
parents: 67
diff changeset
421
kono
parents: 67
diff changeset
422 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
423 ++env;
kono
parents: 67
diff changeset
424 if (*env == '\0')
kono
parents: 67
diff changeset
425 goto invalid;
kono
parents: 67
diff changeset
426
kono
parents: 67
diff changeset
427 for (i = 2; i < 5; i++)
kono
parents: 67
diff changeset
428 if (strncasecmp (env, kinds[i].name, kinds[i].len) == 0)
kono
parents: 67
diff changeset
429 {
kono
parents: 67
diff changeset
430 value = kinds[i].kind;
kono
parents: 67
diff changeset
431 env += kinds[i].len;
kono
parents: 67
diff changeset
432 break;
kono
parents: 67
diff changeset
433 }
kono
parents: 67
diff changeset
434 if (i == 5)
kono
parents: 67
diff changeset
435 goto invalid;
kono
parents: 67
diff changeset
436
kono
parents: 67
diff changeset
437 values[nvalues++] = value;
kono
parents: 67
diff changeset
438 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
439 ++env;
kono
parents: 67
diff changeset
440 if (*env == '\0')
kono
parents: 67
diff changeset
441 break;
kono
parents: 67
diff changeset
442 if (*env != ',')
kono
parents: 67
diff changeset
443 goto invalid;
kono
parents: 67
diff changeset
444 }
kono
parents: 67
diff changeset
445 while (1);
kono
parents: 67
diff changeset
446 *p1stvalue = values[0];
kono
parents: 67
diff changeset
447 *pvalues = values;
kono
parents: 67
diff changeset
448 *pnvalues = nvalues;
kono
parents: 67
diff changeset
449 return true;
kono
parents: 67
diff changeset
450 }
kono
parents: 67
diff changeset
451 goto invalid;
kono
parents: 67
diff changeset
452 }
kono
parents: 67
diff changeset
453
kono
parents: 67
diff changeset
454 *p1stvalue = value;
kono
parents: 67
diff changeset
455 return true;
kono
parents: 67
diff changeset
456
kono
parents: 67
diff changeset
457 invalid:
kono
parents: 67
diff changeset
458 free (values);
kono
parents: 67
diff changeset
459 gomp_error ("Invalid value for environment variable %s", name);
kono
parents: 67
diff changeset
460 return false;
kono
parents: 67
diff changeset
461 }
kono
parents: 67
diff changeset
462
kono
parents: 67
diff changeset
463 static bool
kono
parents: 67
diff changeset
464 parse_one_place (char **envp, bool *negatep, unsigned long *lenp,
kono
parents: 67
diff changeset
465 long *stridep)
kono
parents: 67
diff changeset
466 {
kono
parents: 67
diff changeset
467 char *env = *envp, *start;
kono
parents: 67
diff changeset
468 void *p = gomp_places_list ? gomp_places_list[gomp_places_list_len] : NULL;
kono
parents: 67
diff changeset
469 unsigned long len = 1;
kono
parents: 67
diff changeset
470 long stride = 1;
kono
parents: 67
diff changeset
471 int pass;
kono
parents: 67
diff changeset
472 bool any_negate = false;
kono
parents: 67
diff changeset
473 *negatep = false;
kono
parents: 67
diff changeset
474 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
475 ++env;
kono
parents: 67
diff changeset
476 if (*env == '!')
kono
parents: 67
diff changeset
477 {
kono
parents: 67
diff changeset
478 *negatep = true;
kono
parents: 67
diff changeset
479 ++env;
kono
parents: 67
diff changeset
480 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
481 ++env;
kono
parents: 67
diff changeset
482 }
kono
parents: 67
diff changeset
483 if (*env != '{')
kono
parents: 67
diff changeset
484 return false;
kono
parents: 67
diff changeset
485 ++env;
kono
parents: 67
diff changeset
486 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
487 ++env;
kono
parents: 67
diff changeset
488 start = env;
kono
parents: 67
diff changeset
489 for (pass = 0; pass < (any_negate ? 2 : 1); pass++)
kono
parents: 67
diff changeset
490 {
kono
parents: 67
diff changeset
491 env = start;
kono
parents: 67
diff changeset
492 do
kono
parents: 67
diff changeset
493 {
kono
parents: 67
diff changeset
494 unsigned long this_num, this_len = 1;
kono
parents: 67
diff changeset
495 long this_stride = 1;
kono
parents: 67
diff changeset
496 bool this_negate = (*env == '!');
kono
parents: 67
diff changeset
497 if (this_negate)
kono
parents: 67
diff changeset
498 {
kono
parents: 67
diff changeset
499 if (gomp_places_list)
kono
parents: 67
diff changeset
500 any_negate = true;
kono
parents: 67
diff changeset
501 ++env;
kono
parents: 67
diff changeset
502 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
503 ++env;
kono
parents: 67
diff changeset
504 }
kono
parents: 67
diff changeset
505
kono
parents: 67
diff changeset
506 errno = 0;
kono
parents: 67
diff changeset
507 this_num = strtoul (env, &env, 10);
kono
parents: 67
diff changeset
508 if (errno)
kono
parents: 67
diff changeset
509 return false;
kono
parents: 67
diff changeset
510 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
511 ++env;
kono
parents: 67
diff changeset
512 if (*env == ':')
kono
parents: 67
diff changeset
513 {
kono
parents: 67
diff changeset
514 ++env;
kono
parents: 67
diff changeset
515 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
516 ++env;
kono
parents: 67
diff changeset
517 errno = 0;
kono
parents: 67
diff changeset
518 this_len = strtoul (env, &env, 10);
kono
parents: 67
diff changeset
519 if (errno || this_len == 0)
kono
parents: 67
diff changeset
520 return false;
kono
parents: 67
diff changeset
521 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
522 ++env;
kono
parents: 67
diff changeset
523 if (*env == ':')
kono
parents: 67
diff changeset
524 {
kono
parents: 67
diff changeset
525 ++env;
kono
parents: 67
diff changeset
526 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
527 ++env;
kono
parents: 67
diff changeset
528 errno = 0;
kono
parents: 67
diff changeset
529 this_stride = strtol (env, &env, 10);
kono
parents: 67
diff changeset
530 if (errno)
kono
parents: 67
diff changeset
531 return false;
kono
parents: 67
diff changeset
532 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
533 ++env;
kono
parents: 67
diff changeset
534 }
kono
parents: 67
diff changeset
535 }
kono
parents: 67
diff changeset
536 if (this_negate && this_len != 1)
kono
parents: 67
diff changeset
537 return false;
kono
parents: 67
diff changeset
538 if (gomp_places_list && pass == this_negate)
kono
parents: 67
diff changeset
539 {
kono
parents: 67
diff changeset
540 if (this_negate)
kono
parents: 67
diff changeset
541 {
kono
parents: 67
diff changeset
542 if (!gomp_affinity_remove_cpu (p, this_num))
kono
parents: 67
diff changeset
543 return false;
kono
parents: 67
diff changeset
544 }
kono
parents: 67
diff changeset
545 else if (!gomp_affinity_add_cpus (p, this_num, this_len,
kono
parents: 67
diff changeset
546 this_stride, false))
kono
parents: 67
diff changeset
547 return false;
kono
parents: 67
diff changeset
548 }
kono
parents: 67
diff changeset
549 if (*env == '}')
kono
parents: 67
diff changeset
550 break;
kono
parents: 67
diff changeset
551 if (*env != ',')
kono
parents: 67
diff changeset
552 return false;
kono
parents: 67
diff changeset
553 ++env;
kono
parents: 67
diff changeset
554 }
kono
parents: 67
diff changeset
555 while (1);
kono
parents: 67
diff changeset
556 }
kono
parents: 67
diff changeset
557
kono
parents: 67
diff changeset
558 ++env;
kono
parents: 67
diff changeset
559 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
560 ++env;
kono
parents: 67
diff changeset
561 if (*env == ':')
kono
parents: 67
diff changeset
562 {
kono
parents: 67
diff changeset
563 ++env;
kono
parents: 67
diff changeset
564 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
565 ++env;
kono
parents: 67
diff changeset
566 errno = 0;
kono
parents: 67
diff changeset
567 len = strtoul (env, &env, 10);
kono
parents: 67
diff changeset
568 if (errno || len == 0 || len >= 65536)
kono
parents: 67
diff changeset
569 return false;
kono
parents: 67
diff changeset
570 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
571 ++env;
kono
parents: 67
diff changeset
572 if (*env == ':')
kono
parents: 67
diff changeset
573 {
kono
parents: 67
diff changeset
574 ++env;
kono
parents: 67
diff changeset
575 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
576 ++env;
kono
parents: 67
diff changeset
577 errno = 0;
kono
parents: 67
diff changeset
578 stride = strtol (env, &env, 10);
kono
parents: 67
diff changeset
579 if (errno)
kono
parents: 67
diff changeset
580 return false;
kono
parents: 67
diff changeset
581 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
582 ++env;
kono
parents: 67
diff changeset
583 }
kono
parents: 67
diff changeset
584 }
kono
parents: 67
diff changeset
585 if (*negatep && len != 1)
kono
parents: 67
diff changeset
586 return false;
kono
parents: 67
diff changeset
587 *envp = env;
kono
parents: 67
diff changeset
588 *lenp = len;
kono
parents: 67
diff changeset
589 *stridep = stride;
kono
parents: 67
diff changeset
590 return true;
kono
parents: 67
diff changeset
591 }
kono
parents: 67
diff changeset
592
kono
parents: 67
diff changeset
593 static bool
kono
parents: 67
diff changeset
594 parse_places_var (const char *name, bool ignore)
kono
parents: 67
diff changeset
595 {
kono
parents: 67
diff changeset
596 char *env = getenv (name), *end;
kono
parents: 67
diff changeset
597 bool any_negate = false;
kono
parents: 67
diff changeset
598 int level = 0;
kono
parents: 67
diff changeset
599 unsigned long count = 0;
kono
parents: 67
diff changeset
600 if (env == NULL)
kono
parents: 67
diff changeset
601 return false;
kono
parents: 67
diff changeset
602
kono
parents: 67
diff changeset
603 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
604 ++env;
kono
parents: 67
diff changeset
605 if (*env == '\0')
kono
parents: 67
diff changeset
606 goto invalid;
kono
parents: 67
diff changeset
607
kono
parents: 67
diff changeset
608 if (strncasecmp (env, "threads", 7) == 0)
kono
parents: 67
diff changeset
609 {
kono
parents: 67
diff changeset
610 env += 7;
kono
parents: 67
diff changeset
611 level = 1;
kono
parents: 67
diff changeset
612 }
kono
parents: 67
diff changeset
613 else if (strncasecmp (env, "cores", 5) == 0)
kono
parents: 67
diff changeset
614 {
kono
parents: 67
diff changeset
615 env += 5;
kono
parents: 67
diff changeset
616 level = 2;
kono
parents: 67
diff changeset
617 }
kono
parents: 67
diff changeset
618 else if (strncasecmp (env, "sockets", 7) == 0)
kono
parents: 67
diff changeset
619 {
kono
parents: 67
diff changeset
620 env += 7;
kono
parents: 67
diff changeset
621 level = 3;
kono
parents: 67
diff changeset
622 }
kono
parents: 67
diff changeset
623 if (level)
kono
parents: 67
diff changeset
624 {
kono
parents: 67
diff changeset
625 count = ULONG_MAX;
kono
parents: 67
diff changeset
626 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
627 ++env;
kono
parents: 67
diff changeset
628 if (*env != '\0')
kono
parents: 67
diff changeset
629 {
kono
parents: 67
diff changeset
630 if (*env++ != '(')
kono
parents: 67
diff changeset
631 goto invalid;
kono
parents: 67
diff changeset
632 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
633 ++env;
kono
parents: 67
diff changeset
634
kono
parents: 67
diff changeset
635 errno = 0;
kono
parents: 67
diff changeset
636 count = strtoul (env, &end, 10);
kono
parents: 67
diff changeset
637 if (errno)
kono
parents: 67
diff changeset
638 goto invalid;
kono
parents: 67
diff changeset
639 env = end;
kono
parents: 67
diff changeset
640 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
641 ++env;
kono
parents: 67
diff changeset
642 if (*env != ')')
kono
parents: 67
diff changeset
643 goto invalid;
kono
parents: 67
diff changeset
644 ++env;
kono
parents: 67
diff changeset
645 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
646 ++env;
kono
parents: 67
diff changeset
647 if (*env != '\0')
kono
parents: 67
diff changeset
648 goto invalid;
kono
parents: 67
diff changeset
649 }
kono
parents: 67
diff changeset
650
kono
parents: 67
diff changeset
651 if (ignore)
kono
parents: 67
diff changeset
652 return false;
kono
parents: 67
diff changeset
653
kono
parents: 67
diff changeset
654 return gomp_affinity_init_level (level, count, false);
kono
parents: 67
diff changeset
655 }
kono
parents: 67
diff changeset
656
kono
parents: 67
diff changeset
657 count = 0;
kono
parents: 67
diff changeset
658 end = env;
kono
parents: 67
diff changeset
659 do
kono
parents: 67
diff changeset
660 {
kono
parents: 67
diff changeset
661 bool negate;
kono
parents: 67
diff changeset
662 unsigned long len;
kono
parents: 67
diff changeset
663 long stride;
kono
parents: 67
diff changeset
664 if (!parse_one_place (&end, &negate, &len, &stride))
kono
parents: 67
diff changeset
665 goto invalid;
kono
parents: 67
diff changeset
666 if (negate)
kono
parents: 67
diff changeset
667 {
kono
parents: 67
diff changeset
668 if (!any_negate)
kono
parents: 67
diff changeset
669 count++;
kono
parents: 67
diff changeset
670 any_negate = true;
kono
parents: 67
diff changeset
671 }
kono
parents: 67
diff changeset
672 else
kono
parents: 67
diff changeset
673 count += len;
kono
parents: 67
diff changeset
674 if (count > 65536)
kono
parents: 67
diff changeset
675 goto invalid;
kono
parents: 67
diff changeset
676 if (*end == '\0')
kono
parents: 67
diff changeset
677 break;
kono
parents: 67
diff changeset
678 if (*end != ',')
kono
parents: 67
diff changeset
679 goto invalid;
kono
parents: 67
diff changeset
680 end++;
kono
parents: 67
diff changeset
681 }
kono
parents: 67
diff changeset
682 while (1);
kono
parents: 67
diff changeset
683
kono
parents: 67
diff changeset
684 if (ignore)
kono
parents: 67
diff changeset
685 return false;
kono
parents: 67
diff changeset
686
kono
parents: 67
diff changeset
687 gomp_places_list_len = 0;
kono
parents: 67
diff changeset
688 gomp_places_list = gomp_affinity_alloc (count, false);
kono
parents: 67
diff changeset
689 if (gomp_places_list == NULL)
kono
parents: 67
diff changeset
690 return false;
kono
parents: 67
diff changeset
691
kono
parents: 67
diff changeset
692 do
kono
parents: 67
diff changeset
693 {
kono
parents: 67
diff changeset
694 bool negate;
kono
parents: 67
diff changeset
695 unsigned long len;
kono
parents: 67
diff changeset
696 long stride;
kono
parents: 67
diff changeset
697 gomp_affinity_init_place (gomp_places_list[gomp_places_list_len]);
kono
parents: 67
diff changeset
698 if (!parse_one_place (&env, &negate, &len, &stride))
kono
parents: 67
diff changeset
699 goto invalid;
kono
parents: 67
diff changeset
700 if (negate)
kono
parents: 67
diff changeset
701 {
kono
parents: 67
diff changeset
702 void *p;
kono
parents: 67
diff changeset
703 for (count = 0; count < gomp_places_list_len; count++)
kono
parents: 67
diff changeset
704 if (gomp_affinity_same_place
kono
parents: 67
diff changeset
705 (gomp_places_list[count],
kono
parents: 67
diff changeset
706 gomp_places_list[gomp_places_list_len]))
kono
parents: 67
diff changeset
707 break;
kono
parents: 67
diff changeset
708 if (count == gomp_places_list_len)
kono
parents: 67
diff changeset
709 {
kono
parents: 67
diff changeset
710 gomp_error ("Trying to remove a non-existing place from list "
kono
parents: 67
diff changeset
711 "of places");
kono
parents: 67
diff changeset
712 goto invalid;
kono
parents: 67
diff changeset
713 }
kono
parents: 67
diff changeset
714 p = gomp_places_list[count];
kono
parents: 67
diff changeset
715 memmove (&gomp_places_list[count],
kono
parents: 67
diff changeset
716 &gomp_places_list[count + 1],
kono
parents: 67
diff changeset
717 (gomp_places_list_len - count - 1) * sizeof (void *));
kono
parents: 67
diff changeset
718 --gomp_places_list_len;
kono
parents: 67
diff changeset
719 gomp_places_list[gomp_places_list_len] = p;
kono
parents: 67
diff changeset
720 }
kono
parents: 67
diff changeset
721 else if (len == 1)
kono
parents: 67
diff changeset
722 ++gomp_places_list_len;
kono
parents: 67
diff changeset
723 else
kono
parents: 67
diff changeset
724 {
kono
parents: 67
diff changeset
725 for (count = 0; count < len - 1; count++)
kono
parents: 67
diff changeset
726 if (!gomp_affinity_copy_place
kono
parents: 67
diff changeset
727 (gomp_places_list[gomp_places_list_len + count + 1],
kono
parents: 67
diff changeset
728 gomp_places_list[gomp_places_list_len + count],
kono
parents: 67
diff changeset
729 stride))
kono
parents: 67
diff changeset
730 goto invalid;
kono
parents: 67
diff changeset
731 gomp_places_list_len += len;
kono
parents: 67
diff changeset
732 }
kono
parents: 67
diff changeset
733 if (*env == '\0')
kono
parents: 67
diff changeset
734 break;
kono
parents: 67
diff changeset
735 env++;
kono
parents: 67
diff changeset
736 }
kono
parents: 67
diff changeset
737 while (1);
kono
parents: 67
diff changeset
738
kono
parents: 67
diff changeset
739 if (gomp_places_list_len == 0)
kono
parents: 67
diff changeset
740 {
kono
parents: 67
diff changeset
741 gomp_error ("All places have been removed");
kono
parents: 67
diff changeset
742 goto invalid;
kono
parents: 67
diff changeset
743 }
kono
parents: 67
diff changeset
744 if (!gomp_affinity_finalize_place_list (false))
kono
parents: 67
diff changeset
745 goto invalid;
kono
parents: 67
diff changeset
746 return true;
kono
parents: 67
diff changeset
747
kono
parents: 67
diff changeset
748 invalid:
kono
parents: 67
diff changeset
749 free (gomp_places_list);
kono
parents: 67
diff changeset
750 gomp_places_list = NULL;
kono
parents: 67
diff changeset
751 gomp_places_list_len = 0;
kono
parents: 67
diff changeset
752 gomp_error ("Invalid value for environment variable %s", name);
kono
parents: 67
diff changeset
753 return false;
kono
parents: 67
diff changeset
754 }
kono
parents: 67
diff changeset
755
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 /* Parse the OMP_STACKSIZE environment varible. Return true if one was
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 present and it was successfully parsed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 parse_stacksize (const char *name, unsigned long *pvalue)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 char *env, *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 unsigned long value, shift = 10;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 env = getenv (name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 if (env == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 if (*env == '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 errno = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 value = strtoul (env, &end, 10);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 if (errno)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 while (isspace ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 if (*end != '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 switch (tolower ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 case 'b':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 shift = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 case 'k':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 case 'm':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 shift = 20;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 case 'g':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 shift = 30;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 while (isspace ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 if (*end != '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
805
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 if (((value << shift) >> shift) != value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 *pvalue = value << shift;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 invalid:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 gomp_error ("Invalid value for environment variable %s", name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
816
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 /* Parse the GOMP_SPINCOUNT environment varible. Return true if one was
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
818 present and it was successfully parsed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 parse_spincount (const char *name, unsigned long long *pvalue)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 char *env, *end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 unsigned long long value, mult = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 env = getenv (name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 if (env == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 if (*env == '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 if (strncasecmp (env, "infinite", 8) == 0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 || strncasecmp (env, "infinity", 8) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 value = ~0ULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 end = env + 8;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 goto check_tail;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 errno = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 value = strtoull (env, &end, 10);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 if (errno)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 while (isspace ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 if (*end != '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 switch (tolower ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 case 'k':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 mult = 1000LL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 case 'm':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 mult = 1000LL * 1000LL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 case 'g':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 mult = 1000LL * 1000LL * 1000LL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 case 't':
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 mult = 1000LL * 1000LL * 1000LL * 1000LL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870 check_tail:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 while (isspace ((unsigned char) *end))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 ++end;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873 if (*end != '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 if (value > ~0ULL / mult)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 value = ~0ULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 value *= mult;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 *pvalue = value;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885 invalid:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 gomp_error ("Invalid value for environment variable %s", name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890 /* Parse a boolean value for environment variable NAME and store the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 result in VALUE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
893 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 parse_boolean (const char *name, bool *value)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 const char *env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898 env = getenv (name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
899 if (env == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
900 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
901
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
902 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 if (strncasecmp (env, "true", 4) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 *value = true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 env += 4;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909 else if (strncasecmp (env, "false", 5) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 *value = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 env += 5;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
914 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915 env = "X";
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 if (*env != '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 gomp_error ("Invalid value for environment variable %s", name);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 /* Parse the OMP_WAIT_POLICY environment variable and store the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 result in gomp_active_wait_policy. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
924
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925 static int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926 parse_wait_policy (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 const char *env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 int ret = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
931 env = getenv ("OMP_WAIT_POLICY");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
932 if (env == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 return -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 if (strncasecmp (env, "active", 6) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 ret = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 env += 6;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 else if (strncasecmp (env, "passive", 7) == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 ret = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945 env += 7;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
946 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 env = "X";
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 while (isspace ((unsigned char) *env))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 ++env;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
951 if (*env == '\0')
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
952 return ret;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
953 gomp_error ("Invalid value for environment variable OMP_WAIT_POLICY");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 return -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
956
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 /* Parse the GOMP_CPU_AFFINITY environment varible. Return true if one was
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 present and it was successfully parsed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 static bool
111
kono
parents: 67
diff changeset
961 parse_affinity (bool ignore)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 {
111
kono
parents: 67
diff changeset
963 char *env, *end, *start;
kono
parents: 67
diff changeset
964 int pass;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 unsigned long cpu_beg, cpu_end, cpu_stride;
111
kono
parents: 67
diff changeset
966 size_t count = 0, needed;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
967
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
968 env = getenv ("GOMP_CPU_AFFINITY");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
969 if (env == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
970 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
971
111
kono
parents: 67
diff changeset
972 start = env;
kono
parents: 67
diff changeset
973 for (pass = 0; pass < 2; pass++)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 {
111
kono
parents: 67
diff changeset
975 env = start;
kono
parents: 67
diff changeset
976 if (pass == 1)
kono
parents: 67
diff changeset
977 {
kono
parents: 67
diff changeset
978 if (ignore)
kono
parents: 67
diff changeset
979 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980
111
kono
parents: 67
diff changeset
981 gomp_places_list_len = 0;
kono
parents: 67
diff changeset
982 gomp_places_list = gomp_affinity_alloc (count, true);
kono
parents: 67
diff changeset
983 if (gomp_places_list == NULL)
kono
parents: 67
diff changeset
984 return false;
kono
parents: 67
diff changeset
985 }
kono
parents: 67
diff changeset
986 do
kono
parents: 67
diff changeset
987 {
kono
parents: 67
diff changeset
988 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
989 ++env;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990
111
kono
parents: 67
diff changeset
991 errno = 0;
kono
parents: 67
diff changeset
992 cpu_beg = strtoul (env, &end, 0);
kono
parents: 67
diff changeset
993 if (errno || cpu_beg >= 65536)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 goto invalid;
111
kono
parents: 67
diff changeset
995 cpu_end = cpu_beg;
kono
parents: 67
diff changeset
996 cpu_stride = 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 env = end;
111
kono
parents: 67
diff changeset
999 if (*env == '-')
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 {
111
kono
parents: 67
diff changeset
1001 errno = 0;
kono
parents: 67
diff changeset
1002 cpu_end = strtoul (++env, &end, 0);
kono
parents: 67
diff changeset
1003 if (errno || cpu_end >= 65536 || cpu_end < cpu_beg)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 goto invalid;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 env = end;
111
kono
parents: 67
diff changeset
1007 if (*env == ':')
kono
parents: 67
diff changeset
1008 {
kono
parents: 67
diff changeset
1009 errno = 0;
kono
parents: 67
diff changeset
1010 cpu_stride = strtoul (++env, &end, 0);
kono
parents: 67
diff changeset
1011 if (errno || cpu_stride == 0 || cpu_stride >= 65536)
kono
parents: 67
diff changeset
1012 goto invalid;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013
111
kono
parents: 67
diff changeset
1014 env = end;
kono
parents: 67
diff changeset
1015 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017
111
kono
parents: 67
diff changeset
1018 needed = (cpu_end - cpu_beg) / cpu_stride + 1;
kono
parents: 67
diff changeset
1019 if (pass == 0)
kono
parents: 67
diff changeset
1020 count += needed;
kono
parents: 67
diff changeset
1021 else
kono
parents: 67
diff changeset
1022 {
kono
parents: 67
diff changeset
1023 while (needed--)
kono
parents: 67
diff changeset
1024 {
kono
parents: 67
diff changeset
1025 void *p = gomp_places_list[gomp_places_list_len];
kono
parents: 67
diff changeset
1026 gomp_affinity_init_place (p);
kono
parents: 67
diff changeset
1027 if (gomp_affinity_add_cpus (p, cpu_beg, 1, 0, true))
kono
parents: 67
diff changeset
1028 ++gomp_places_list_len;
kono
parents: 67
diff changeset
1029 cpu_beg += cpu_stride;
kono
parents: 67
diff changeset
1030 }
kono
parents: 67
diff changeset
1031 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032
111
kono
parents: 67
diff changeset
1033 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
1034 ++env;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035
111
kono
parents: 67
diff changeset
1036 if (*env == ',')
kono
parents: 67
diff changeset
1037 env++;
kono
parents: 67
diff changeset
1038 else if (*env == '\0')
kono
parents: 67
diff changeset
1039 break;
kono
parents: 67
diff changeset
1040 }
kono
parents: 67
diff changeset
1041 while (1);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043
111
kono
parents: 67
diff changeset
1044 if (gomp_places_list_len == 0)
kono
parents: 67
diff changeset
1045 {
kono
parents: 67
diff changeset
1046 free (gomp_places_list);
kono
parents: 67
diff changeset
1047 gomp_places_list = NULL;
kono
parents: 67
diff changeset
1048 return false;
kono
parents: 67
diff changeset
1049 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 invalid:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 gomp_error ("Invalid value for enviroment variable GOMP_CPU_AFFINITY");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1055 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1056
111
kono
parents: 67
diff changeset
1057 static void
kono
parents: 67
diff changeset
1058 parse_acc_device_type (void)
kono
parents: 67
diff changeset
1059 {
kono
parents: 67
diff changeset
1060 const char *env = getenv ("ACC_DEVICE_TYPE");
kono
parents: 67
diff changeset
1061
kono
parents: 67
diff changeset
1062 if (env && *env != '\0')
kono
parents: 67
diff changeset
1063 goacc_device_type = strdup (env);
kono
parents: 67
diff changeset
1064 else
kono
parents: 67
diff changeset
1065 goacc_device_type = NULL;
kono
parents: 67
diff changeset
1066 }
kono
parents: 67
diff changeset
1067
kono
parents: 67
diff changeset
1068 static void
kono
parents: 67
diff changeset
1069 handle_omp_display_env (unsigned long stacksize, int wait_policy)
kono
parents: 67
diff changeset
1070 {
kono
parents: 67
diff changeset
1071 const char *env;
kono
parents: 67
diff changeset
1072 bool display = false;
kono
parents: 67
diff changeset
1073 bool verbose = false;
kono
parents: 67
diff changeset
1074 int i;
kono
parents: 67
diff changeset
1075
kono
parents: 67
diff changeset
1076 env = getenv ("OMP_DISPLAY_ENV");
kono
parents: 67
diff changeset
1077 if (env == NULL)
kono
parents: 67
diff changeset
1078 return;
kono
parents: 67
diff changeset
1079
kono
parents: 67
diff changeset
1080 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
1081 ++env;
kono
parents: 67
diff changeset
1082 if (strncasecmp (env, "true", 4) == 0)
kono
parents: 67
diff changeset
1083 {
kono
parents: 67
diff changeset
1084 display = true;
kono
parents: 67
diff changeset
1085 env += 4;
kono
parents: 67
diff changeset
1086 }
kono
parents: 67
diff changeset
1087 else if (strncasecmp (env, "false", 5) == 0)
kono
parents: 67
diff changeset
1088 {
kono
parents: 67
diff changeset
1089 display = false;
kono
parents: 67
diff changeset
1090 env += 5;
kono
parents: 67
diff changeset
1091 }
kono
parents: 67
diff changeset
1092 else if (strncasecmp (env, "verbose", 7) == 0)
kono
parents: 67
diff changeset
1093 {
kono
parents: 67
diff changeset
1094 display = true;
kono
parents: 67
diff changeset
1095 verbose = true;
kono
parents: 67
diff changeset
1096 env += 7;
kono
parents: 67
diff changeset
1097 }
kono
parents: 67
diff changeset
1098 else
kono
parents: 67
diff changeset
1099 env = "X";
kono
parents: 67
diff changeset
1100 while (isspace ((unsigned char) *env))
kono
parents: 67
diff changeset
1101 ++env;
kono
parents: 67
diff changeset
1102 if (*env != '\0')
kono
parents: 67
diff changeset
1103 gomp_error ("Invalid value for environment variable OMP_DISPLAY_ENV");
kono
parents: 67
diff changeset
1104
kono
parents: 67
diff changeset
1105 if (!display)
kono
parents: 67
diff changeset
1106 return;
kono
parents: 67
diff changeset
1107
kono
parents: 67
diff changeset
1108 fputs ("\nOPENMP DISPLAY ENVIRONMENT BEGIN\n", stderr);
kono
parents: 67
diff changeset
1109
kono
parents: 67
diff changeset
1110 fputs (" _OPENMP = '201511'\n", stderr);
kono
parents: 67
diff changeset
1111 fprintf (stderr, " OMP_DYNAMIC = '%s'\n",
kono
parents: 67
diff changeset
1112 gomp_global_icv.dyn_var ? "TRUE" : "FALSE");
kono
parents: 67
diff changeset
1113 fprintf (stderr, " OMP_NESTED = '%s'\n",
kono
parents: 67
diff changeset
1114 gomp_global_icv.nest_var ? "TRUE" : "FALSE");
kono
parents: 67
diff changeset
1115
kono
parents: 67
diff changeset
1116 fprintf (stderr, " OMP_NUM_THREADS = '%lu", gomp_global_icv.nthreads_var);
kono
parents: 67
diff changeset
1117 for (i = 1; i < gomp_nthreads_var_list_len; i++)
kono
parents: 67
diff changeset
1118 fprintf (stderr, ",%lu", gomp_nthreads_var_list[i]);
kono
parents: 67
diff changeset
1119 fputs ("'\n", stderr);
kono
parents: 67
diff changeset
1120
kono
parents: 67
diff changeset
1121 fprintf (stderr, " OMP_SCHEDULE = '");
kono
parents: 67
diff changeset
1122 switch (gomp_global_icv.run_sched_var)
kono
parents: 67
diff changeset
1123 {
kono
parents: 67
diff changeset
1124 case GFS_RUNTIME:
kono
parents: 67
diff changeset
1125 fputs ("RUNTIME", stderr);
kono
parents: 67
diff changeset
1126 break;
kono
parents: 67
diff changeset
1127 case GFS_STATIC:
kono
parents: 67
diff changeset
1128 fputs ("STATIC", stderr);
kono
parents: 67
diff changeset
1129 break;
kono
parents: 67
diff changeset
1130 case GFS_DYNAMIC:
kono
parents: 67
diff changeset
1131 fputs ("DYNAMIC", stderr);
kono
parents: 67
diff changeset
1132 break;
kono
parents: 67
diff changeset
1133 case GFS_GUIDED:
kono
parents: 67
diff changeset
1134 fputs ("GUIDED", stderr);
kono
parents: 67
diff changeset
1135 break;
kono
parents: 67
diff changeset
1136 case GFS_AUTO:
kono
parents: 67
diff changeset
1137 fputs ("AUTO", stderr);
kono
parents: 67
diff changeset
1138 break;
kono
parents: 67
diff changeset
1139 }
kono
parents: 67
diff changeset
1140 fputs ("'\n", stderr);
kono
parents: 67
diff changeset
1141
kono
parents: 67
diff changeset
1142 fputs (" OMP_PROC_BIND = '", stderr);
kono
parents: 67
diff changeset
1143 switch (gomp_global_icv.bind_var)
kono
parents: 67
diff changeset
1144 {
kono
parents: 67
diff changeset
1145 case omp_proc_bind_false:
kono
parents: 67
diff changeset
1146 fputs ("FALSE", stderr);
kono
parents: 67
diff changeset
1147 break;
kono
parents: 67
diff changeset
1148 case omp_proc_bind_true:
kono
parents: 67
diff changeset
1149 fputs ("TRUE", stderr);
kono
parents: 67
diff changeset
1150 break;
kono
parents: 67
diff changeset
1151 case omp_proc_bind_master:
kono
parents: 67
diff changeset
1152 fputs ("MASTER", stderr);
kono
parents: 67
diff changeset
1153 break;
kono
parents: 67
diff changeset
1154 case omp_proc_bind_close:
kono
parents: 67
diff changeset
1155 fputs ("CLOSE", stderr);
kono
parents: 67
diff changeset
1156 break;
kono
parents: 67
diff changeset
1157 case omp_proc_bind_spread:
kono
parents: 67
diff changeset
1158 fputs ("SPREAD", stderr);
kono
parents: 67
diff changeset
1159 break;
kono
parents: 67
diff changeset
1160 }
kono
parents: 67
diff changeset
1161 for (i = 1; i < gomp_bind_var_list_len; i++)
kono
parents: 67
diff changeset
1162 switch (gomp_bind_var_list[i])
kono
parents: 67
diff changeset
1163 {
kono
parents: 67
diff changeset
1164 case omp_proc_bind_master:
kono
parents: 67
diff changeset
1165 fputs (",MASTER", stderr);
kono
parents: 67
diff changeset
1166 break;
kono
parents: 67
diff changeset
1167 case omp_proc_bind_close:
kono
parents: 67
diff changeset
1168 fputs (",CLOSE", stderr);
kono
parents: 67
diff changeset
1169 break;
kono
parents: 67
diff changeset
1170 case omp_proc_bind_spread:
kono
parents: 67
diff changeset
1171 fputs (",SPREAD", stderr);
kono
parents: 67
diff changeset
1172 break;
kono
parents: 67
diff changeset
1173 }
kono
parents: 67
diff changeset
1174 fputs ("'\n", stderr);
kono
parents: 67
diff changeset
1175 fputs (" OMP_PLACES = '", stderr);
kono
parents: 67
diff changeset
1176 for (i = 0; i < gomp_places_list_len; i++)
kono
parents: 67
diff changeset
1177 {
kono
parents: 67
diff changeset
1178 fputs ("{", stderr);
kono
parents: 67
diff changeset
1179 gomp_affinity_print_place (gomp_places_list[i]);
kono
parents: 67
diff changeset
1180 fputs (i + 1 == gomp_places_list_len ? "}" : "},", stderr);
kono
parents: 67
diff changeset
1181 }
kono
parents: 67
diff changeset
1182 fputs ("'\n", stderr);
kono
parents: 67
diff changeset
1183
kono
parents: 67
diff changeset
1184 fprintf (stderr, " OMP_STACKSIZE = '%lu'\n", stacksize);
kono
parents: 67
diff changeset
1185
kono
parents: 67
diff changeset
1186 /* GOMP's default value is actually neither active nor passive. */
kono
parents: 67
diff changeset
1187 fprintf (stderr, " OMP_WAIT_POLICY = '%s'\n",
kono
parents: 67
diff changeset
1188 wait_policy > 0 ? "ACTIVE" : "PASSIVE");
kono
parents: 67
diff changeset
1189 fprintf (stderr, " OMP_THREAD_LIMIT = '%u'\n",
kono
parents: 67
diff changeset
1190 gomp_global_icv.thread_limit_var);
kono
parents: 67
diff changeset
1191 fprintf (stderr, " OMP_MAX_ACTIVE_LEVELS = '%lu'\n",
kono
parents: 67
diff changeset
1192 gomp_max_active_levels_var);
kono
parents: 67
diff changeset
1193
kono
parents: 67
diff changeset
1194 fprintf (stderr, " OMP_CANCELLATION = '%s'\n",
kono
parents: 67
diff changeset
1195 gomp_cancel_var ? "TRUE" : "FALSE");
kono
parents: 67
diff changeset
1196 fprintf (stderr, " OMP_DEFAULT_DEVICE = '%d'\n",
kono
parents: 67
diff changeset
1197 gomp_global_icv.default_device_var);
kono
parents: 67
diff changeset
1198 fprintf (stderr, " OMP_MAX_TASK_PRIORITY = '%d'\n",
kono
parents: 67
diff changeset
1199 gomp_max_task_priority_var);
kono
parents: 67
diff changeset
1200
kono
parents: 67
diff changeset
1201 if (verbose)
kono
parents: 67
diff changeset
1202 {
kono
parents: 67
diff changeset
1203 fputs (" GOMP_CPU_AFFINITY = ''\n", stderr);
kono
parents: 67
diff changeset
1204 fprintf (stderr, " GOMP_STACKSIZE = '%lu'\n", stacksize);
kono
parents: 67
diff changeset
1205 #ifdef HAVE_INTTYPES_H
kono
parents: 67
diff changeset
1206 fprintf (stderr, " GOMP_SPINCOUNT = '%"PRIu64"'\n",
kono
parents: 67
diff changeset
1207 (uint64_t) gomp_spin_count_var);
kono
parents: 67
diff changeset
1208 #else
kono
parents: 67
diff changeset
1209 fprintf (stderr, " GOMP_SPINCOUNT = '%lu'\n",
kono
parents: 67
diff changeset
1210 (unsigned long) gomp_spin_count_var);
kono
parents: 67
diff changeset
1211 #endif
kono
parents: 67
diff changeset
1212 }
kono
parents: 67
diff changeset
1213
kono
parents: 67
diff changeset
1214 fputs ("OPENMP DISPLAY ENVIRONMENT END\n", stderr);
kono
parents: 67
diff changeset
1215 }
kono
parents: 67
diff changeset
1216
kono
parents: 67
diff changeset
1217
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218 static void __attribute__((constructor))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1219 initialize_env (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1220 {
111
kono
parents: 67
diff changeset
1221 unsigned long thread_limit_var, stacksize = GOMP_DEFAULT_STACKSIZE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1222 int wait_policy;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1223
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1224 /* Do a compile time check that mkomp_h.pl did good job. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 omp_check_defines ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1226
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1227 parse_schedule ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1228 parse_boolean ("OMP_DYNAMIC", &gomp_global_icv.dyn_var);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1229 parse_boolean ("OMP_NESTED", &gomp_global_icv.nest_var);
111
kono
parents: 67
diff changeset
1230 parse_boolean ("OMP_CANCELLATION", &gomp_cancel_var);
kono
parents: 67
diff changeset
1231 parse_int ("OMP_DEFAULT_DEVICE", &gomp_global_icv.default_device_var, true);
kono
parents: 67
diff changeset
1232 parse_int ("OMP_MAX_TASK_PRIORITY", &gomp_max_task_priority_var, true);
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1233 parse_unsigned_long ("OMP_MAX_ACTIVE_LEVELS", &gomp_max_active_levels_var,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1234 true);
111
kono
parents: 67
diff changeset
1235 if (parse_unsigned_long ("OMP_THREAD_LIMIT", &thread_limit_var, false))
kono
parents: 67
diff changeset
1236 {
kono
parents: 67
diff changeset
1237 gomp_global_icv.thread_limit_var
kono
parents: 67
diff changeset
1238 = thread_limit_var > INT_MAX ? UINT_MAX : thread_limit_var;
kono
parents: 67
diff changeset
1239 }
kono
parents: 67
diff changeset
1240 parse_int_secure ("GOMP_DEBUG", &gomp_debug_var, true);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1241 #ifndef HAVE_SYNC_BUILTINS
111
kono
parents: 67
diff changeset
1242 gomp_mutex_init (&gomp_managed_threads_lock);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1243 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1244 gomp_init_num_threads ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1245 gomp_available_cpus = gomp_global_icv.nthreads_var;
111
kono
parents: 67
diff changeset
1246 if (!parse_unsigned_long_list ("OMP_NUM_THREADS",
kono
parents: 67
diff changeset
1247 &gomp_global_icv.nthreads_var,
kono
parents: 67
diff changeset
1248 &gomp_nthreads_var_list,
kono
parents: 67
diff changeset
1249 &gomp_nthreads_var_list_len))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1250 gomp_global_icv.nthreads_var = gomp_available_cpus;
111
kono
parents: 67
diff changeset
1251 bool ignore = false;
kono
parents: 67
diff changeset
1252 if (parse_bind_var ("OMP_PROC_BIND",
kono
parents: 67
diff changeset
1253 &gomp_global_icv.bind_var,
kono
parents: 67
diff changeset
1254 &gomp_bind_var_list,
kono
parents: 67
diff changeset
1255 &gomp_bind_var_list_len)
kono
parents: 67
diff changeset
1256 && gomp_global_icv.bind_var == omp_proc_bind_false)
kono
parents: 67
diff changeset
1257 ignore = true;
kono
parents: 67
diff changeset
1258 /* Make sure OMP_PLACES and GOMP_CPU_AFFINITY env vars are always
kono
parents: 67
diff changeset
1259 parsed if present in the environment. If OMP_PROC_BIND was set
kono
parents: 67
diff changeset
1260 explictly to false, don't populate places list though. If places
kono
parents: 67
diff changeset
1261 list was successfully set from OMP_PLACES, only parse but don't process
kono
parents: 67
diff changeset
1262 GOMP_CPU_AFFINITY. If OMP_PROC_BIND was not set in the environment,
kono
parents: 67
diff changeset
1263 default to OMP_PROC_BIND=true if OMP_PLACES or GOMP_CPU_AFFINITY
kono
parents: 67
diff changeset
1264 was successfully parsed into a places list, otherwise to
kono
parents: 67
diff changeset
1265 OMP_PROC_BIND=false. */
kono
parents: 67
diff changeset
1266 if (parse_places_var ("OMP_PLACES", ignore))
kono
parents: 67
diff changeset
1267 {
kono
parents: 67
diff changeset
1268 if (gomp_global_icv.bind_var == omp_proc_bind_false)
kono
parents: 67
diff changeset
1269 gomp_global_icv.bind_var = true;
kono
parents: 67
diff changeset
1270 ignore = true;
kono
parents: 67
diff changeset
1271 }
kono
parents: 67
diff changeset
1272 if (parse_affinity (ignore))
kono
parents: 67
diff changeset
1273 {
kono
parents: 67
diff changeset
1274 if (gomp_global_icv.bind_var == omp_proc_bind_false)
kono
parents: 67
diff changeset
1275 gomp_global_icv.bind_var = true;
kono
parents: 67
diff changeset
1276 ignore = true;
kono
parents: 67
diff changeset
1277 }
kono
parents: 67
diff changeset
1278 if (gomp_global_icv.bind_var != omp_proc_bind_false)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 gomp_init_affinity ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280 wait_policy = parse_wait_policy ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1281 if (!parse_spincount ("GOMP_SPINCOUNT", &gomp_spin_count_var))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1282 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 /* Using a rough estimation of 100000 spins per msec,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1284 use 5 min blocking for OMP_WAIT_POLICY=active,
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1285 3 msec blocking when OMP_WAIT_POLICY is not specificed
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1286 and 0 when OMP_WAIT_POLICY=passive.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1287 Depending on the CPU speed, this can be e.g. 5 times longer
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1288 or 5 times shorter. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1289 if (wait_policy > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1290 gomp_spin_count_var = 30000000000LL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1291 else if (wait_policy < 0)
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
1292 gomp_spin_count_var = 300000LL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1293 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1294 /* gomp_throttled_spin_count_var is used when there are more libgomp
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1295 managed threads than available CPUs. Use very short spinning. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1296 if (wait_policy > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1297 gomp_throttled_spin_count_var = 1000LL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298 else if (wait_policy < 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299 gomp_throttled_spin_count_var = 100LL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1300 if (gomp_throttled_spin_count_var > gomp_spin_count_var)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301 gomp_throttled_spin_count_var = gomp_spin_count_var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 /* Not strictly environment related, but ordering constructors is tricky. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 pthread_attr_init (&gomp_thread_attr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 pthread_attr_setdetachstate (&gomp_thread_attr, PTHREAD_CREATE_DETACHED);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 if (parse_stacksize ("OMP_STACKSIZE", &stacksize)
111
kono
parents: 67
diff changeset
1308 || parse_stacksize ("GOMP_STACKSIZE", &stacksize)
kono
parents: 67
diff changeset
1309 || GOMP_DEFAULT_STACKSIZE)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311 int err;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313 err = pthread_attr_setstacksize (&gomp_thread_attr, stacksize);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 #ifdef PTHREAD_STACK_MIN
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316 if (err == EINVAL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1317 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1318 if (stacksize < PTHREAD_STACK_MIN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1319 gomp_error ("Stack size less than minimum of %luk",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 PTHREAD_STACK_MIN / 1024ul
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 + (PTHREAD_STACK_MIN % 1024 != 0));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323 gomp_error ("Stack size larger than system limit");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 if (err != 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328 gomp_error ("Stack size change failed: %s", strerror (err));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330
111
kono
parents: 67
diff changeset
1331 handle_omp_display_env (stacksize, wait_policy);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332
111
kono
parents: 67
diff changeset
1333 /* OpenACC. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334
111
kono
parents: 67
diff changeset
1335 if (!parse_int ("ACC_DEVICE_NUM", &goacc_device_num, true))
kono
parents: 67
diff changeset
1336 goacc_device_num = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1337
111
kono
parents: 67
diff changeset
1338 parse_acc_device_type ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339
111
kono
parents: 67
diff changeset
1340 goacc_runtime_initialize ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1341 }
111
kono
parents: 67
diff changeset
1342 #endif /* LIBGOMP_OFFLOADED_ONLY */