annotate libgomp/env.c @ 158:494b0b89df80 default tip

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