comparison libgomp/parallel.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Copyright (C) 2005-2018 Free Software Foundation, Inc. 1 /* Copyright (C) 2005-2020 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>. 2 Contributed by Richard Henderson <rth@redhat.com>.
3 3
4 This file is part of the GNU Offloading and Multi Processing Library 4 This file is part of the GNU Offloading and Multi Processing Library
5 (libgomp). 5 (libgomp).
6 6
121 121
122 void 122 void
123 GOMP_parallel_start (void (*fn) (void *), void *data, unsigned num_threads) 123 GOMP_parallel_start (void (*fn) (void *), void *data, unsigned num_threads)
124 { 124 {
125 num_threads = gomp_resolve_num_threads (num_threads, 0); 125 num_threads = gomp_resolve_num_threads (num_threads, 0);
126 gomp_team_start (fn, data, num_threads, 0, gomp_new_team (num_threads)); 126 gomp_team_start (fn, data, num_threads, 0, gomp_new_team (num_threads),
127 NULL);
127 } 128 }
128 129
129 void 130 void
130 GOMP_parallel_end (void) 131 GOMP_parallel_end (void)
131 { 132 {
159 gomp_team_end (); 160 gomp_team_end ();
160 } 161 }
161 ialias (GOMP_parallel_end) 162 ialias (GOMP_parallel_end)
162 163
163 void 164 void
164 GOMP_parallel (void (*fn) (void *), void *data, unsigned num_threads, unsigned int flags) 165 GOMP_parallel (void (*fn) (void *), void *data, unsigned num_threads,
166 unsigned int flags)
165 { 167 {
166 num_threads = gomp_resolve_num_threads (num_threads, 0); 168 num_threads = gomp_resolve_num_threads (num_threads, 0);
167 gomp_team_start (fn, data, num_threads, flags, gomp_new_team (num_threads)); 169 gomp_team_start (fn, data, num_threads, flags, gomp_new_team (num_threads),
170 NULL);
168 fn (data); 171 fn (data);
169 ialias_call (GOMP_parallel_end) (); 172 ialias_call (GOMP_parallel_end) ();
173 }
174
175 unsigned
176 GOMP_parallel_reductions (void (*fn) (void *), void *data,
177 unsigned num_threads, unsigned int flags)
178 {
179 struct gomp_taskgroup *taskgroup;
180 num_threads = gomp_resolve_num_threads (num_threads, 0);
181 uintptr_t *rdata = *(uintptr_t **)data;
182 taskgroup = gomp_parallel_reduction_register (rdata, num_threads);
183 gomp_team_start (fn, data, num_threads, flags, gomp_new_team (num_threads),
184 taskgroup);
185 fn (data);
186 ialias_call (GOMP_parallel_end) ();
187 gomp_sem_destroy (&taskgroup->taskgroup_sem);
188 free (taskgroup);
189 return num_threads;
170 } 190 }
171 191
172 bool 192 bool
173 GOMP_cancellation_point (int which) 193 GOMP_cancellation_point (int which)
174 { 194 {
183 return false; 203 return false;
184 return team->work_share_cancelled != 0; 204 return team->work_share_cancelled != 0;
185 } 205 }
186 else if (which & GOMP_CANCEL_TASKGROUP) 206 else if (which & GOMP_CANCEL_TASKGROUP)
187 { 207 {
188 if (thr->task->taskgroup && thr->task->taskgroup->cancelled) 208 if (thr->task->taskgroup)
189 return true; 209 {
210 if (thr->task->taskgroup->cancelled)
211 return true;
212 if (thr->task->taskgroup->workshare
213 && thr->task->taskgroup->prev
214 && thr->task->taskgroup->prev->cancelled)
215 return true;
216 }
190 /* FALLTHRU into the GOMP_CANCEL_PARALLEL case, 217 /* FALLTHRU into the GOMP_CANCEL_PARALLEL case,
191 as #pragma omp cancel parallel also cancels all explicit 218 as #pragma omp cancel parallel also cancels all explicit
192 tasks. */ 219 tasks. */
193 } 220 }
194 if (team) 221 if (team)
216 team->work_share_cancelled = 1; 243 team->work_share_cancelled = 1;
217 return true; 244 return true;
218 } 245 }
219 else if (which & GOMP_CANCEL_TASKGROUP) 246 else if (which & GOMP_CANCEL_TASKGROUP)
220 { 247 {
221 if (thr->task->taskgroup && !thr->task->taskgroup->cancelled) 248 if (thr->task->taskgroup)
222 { 249 {
223 gomp_mutex_lock (&team->task_lock); 250 struct gomp_taskgroup *taskgroup = thr->task->taskgroup;
224 thr->task->taskgroup->cancelled = true; 251 if (taskgroup->workshare && taskgroup->prev)
225 gomp_mutex_unlock (&team->task_lock); 252 taskgroup = taskgroup->prev;
253 if (!taskgroup->cancelled)
254 {
255 gomp_mutex_lock (&team->task_lock);
256 taskgroup->cancelled = true;
257 gomp_mutex_unlock (&team->task_lock);
258 }
226 } 259 }
227 return true; 260 return true;
228 } 261 }
229 team->team_cancelled = 1; 262 team->team_cancelled = 1;
230 gomp_team_barrier_cancel (team); 263 gomp_team_barrier_cancel (team);