annotate libgomp/env.c @ 143:76e1cf5455ef

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