annotate libgomp/parallel.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents: 67
diff changeset
1 /* Copyright (C) 2005-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 Contributed by Richard Henderson <rth@redhat.com>.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
111
kono
parents: 67
diff changeset
4 This file is part of the GNU Offloading and Multi Processing Library
kono
parents: 67
diff changeset
5 (libgomp).
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 Libgomp is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 the Free Software Foundation; either version 3, or (at your option)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 any later version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 /* This file handles the (bare) PARALLEL construct. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "libgomp.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include <limits.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 /* Determine the number of threads to be launched for a PARALLEL construct.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 This algorithm is explicitly described in OpenMP 3.0 section 2.4.1.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 SPECIFIED is a combination of the NUM_THREADS clause and the IF clause.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 If the IF clause is false, SPECIFIED is forced to 1. When NUM_THREADS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 is not present, SPECIFIED is 0. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 unsigned
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 gomp_resolve_num_threads (unsigned specified, unsigned count)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 {
111
kono
parents: 67
diff changeset
41 struct gomp_thread *thr = gomp_thread ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 struct gomp_task_icv *icv;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 unsigned threads_requested, max_num_threads, num_threads;
111
kono
parents: 67
diff changeset
44 unsigned long busy;
kono
parents: 67
diff changeset
45 struct gomp_thread_pool *pool;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 icv = gomp_icv (false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 if (specified == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 return 1;
111
kono
parents: 67
diff changeset
51 else if (thr->ts.active_level >= 1 && !icv->nest_var)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 return 1;
111
kono
parents: 67
diff changeset
53 else if (thr->ts.active_level >= gomp_max_active_levels_var)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 /* If NUM_THREADS not specified, use nthreads_var. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 if (specified == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 threads_requested = icv->nthreads_var;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 threads_requested = specified;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 max_num_threads = threads_requested;
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 /* If dynamic threads are enabled, bound the number of threads
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 that we launch. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 if (icv->dyn_var)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 unsigned dyn = gomp_dynamic_max_threads ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 if (dyn < max_num_threads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 max_num_threads = dyn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 /* Optimization for parallel sections. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 if (count && count < max_num_threads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 max_num_threads = count;
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
111
kono
parents: 67
diff changeset
77 /* UINT_MAX stands for infinity. */
kono
parents: 67
diff changeset
78 if (__builtin_expect (icv->thread_limit_var == UINT_MAX, 1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 || max_num_threads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 return max_num_threads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
111
kono
parents: 67
diff changeset
82 /* The threads_busy counter lives in thread_pool, if there
kono
parents: 67
diff changeset
83 isn't a thread_pool yet, there must be just one thread
kono
parents: 67
diff changeset
84 in the contention group. If thr->team is NULL, this isn't
kono
parents: 67
diff changeset
85 nested parallel, so there is just one thread in the
kono
parents: 67
diff changeset
86 contention group as well, no need to handle it atomically. */
kono
parents: 67
diff changeset
87 pool = thr->thread_pool;
kono
parents: 67
diff changeset
88 if (thr->ts.team == NULL || pool == NULL)
kono
parents: 67
diff changeset
89 {
kono
parents: 67
diff changeset
90 num_threads = max_num_threads;
kono
parents: 67
diff changeset
91 if (num_threads > icv->thread_limit_var)
kono
parents: 67
diff changeset
92 num_threads = icv->thread_limit_var;
kono
parents: 67
diff changeset
93 if (pool)
kono
parents: 67
diff changeset
94 pool->threads_busy = num_threads;
kono
parents: 67
diff changeset
95 return num_threads;
kono
parents: 67
diff changeset
96 }
kono
parents: 67
diff changeset
97
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 #ifdef HAVE_SYNC_BUILTINS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 {
111
kono
parents: 67
diff changeset
101 busy = pool->threads_busy;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 num_threads = max_num_threads;
111
kono
parents: 67
diff changeset
103 if (icv->thread_limit_var - busy + 1 < num_threads)
kono
parents: 67
diff changeset
104 num_threads = icv->thread_limit_var - busy + 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 }
111
kono
parents: 67
diff changeset
106 while (__sync_val_compare_and_swap (&pool->threads_busy,
kono
parents: 67
diff changeset
107 busy, busy + num_threads - 1)
kono
parents: 67
diff changeset
108 != busy);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 #else
111
kono
parents: 67
diff changeset
110 gomp_mutex_lock (&gomp_managed_threads_lock);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 num_threads = max_num_threads;
111
kono
parents: 67
diff changeset
112 busy = pool->threads_busy;
kono
parents: 67
diff changeset
113 if (icv->thread_limit_var - busy + 1 < num_threads)
kono
parents: 67
diff changeset
114 num_threads = icv->thread_limit_var - busy + 1;
kono
parents: 67
diff changeset
115 pool->threads_busy += num_threads - 1;
kono
parents: 67
diff changeset
116 gomp_mutex_unlock (&gomp_managed_threads_lock);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 return num_threads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 GOMP_parallel_start (void (*fn) (void *), void *data, unsigned num_threads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 num_threads = gomp_resolve_num_threads (num_threads, 0);
111
kono
parents: 67
diff changeset
126 gomp_team_start (fn, data, num_threads, 0, gomp_new_team (num_threads));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 GOMP_parallel_end (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 {
111
kono
parents: 67
diff changeset
132 struct gomp_task_icv *icv = gomp_icv (false);
kono
parents: 67
diff changeset
133 if (__builtin_expect (icv->thread_limit_var != UINT_MAX, 0))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 struct gomp_team *team = thr->ts.team;
111
kono
parents: 67
diff changeset
137 unsigned int nthreads = team ? team->nthreads : 1;
kono
parents: 67
diff changeset
138 gomp_team_end ();
kono
parents: 67
diff changeset
139 if (nthreads > 1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 {
111
kono
parents: 67
diff changeset
141 /* If not nested, there is just one thread in the
kono
parents: 67
diff changeset
142 contention group left, no need for atomicity. */
kono
parents: 67
diff changeset
143 if (thr->ts.team == NULL)
kono
parents: 67
diff changeset
144 thr->thread_pool->threads_busy = 1;
kono
parents: 67
diff changeset
145 else
kono
parents: 67
diff changeset
146 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 #ifdef HAVE_SYNC_BUILTINS
111
kono
parents: 67
diff changeset
148 __sync_fetch_and_add (&thr->thread_pool->threads_busy,
kono
parents: 67
diff changeset
149 1UL - nthreads);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 #else
111
kono
parents: 67
diff changeset
151 gomp_mutex_lock (&gomp_managed_threads_lock);
kono
parents: 67
diff changeset
152 thr->thread_pool->threads_busy -= nthreads - 1;
kono
parents: 67
diff changeset
153 gomp_mutex_unlock (&gomp_managed_threads_lock);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 #endif
111
kono
parents: 67
diff changeset
155 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 }
111
kono
parents: 67
diff changeset
158 else
kono
parents: 67
diff changeset
159 gomp_team_end ();
kono
parents: 67
diff changeset
160 }
kono
parents: 67
diff changeset
161 ialias (GOMP_parallel_end)
kono
parents: 67
diff changeset
162
kono
parents: 67
diff changeset
163 void
kono
parents: 67
diff changeset
164 GOMP_parallel (void (*fn) (void *), void *data, unsigned num_threads, unsigned int flags)
kono
parents: 67
diff changeset
165 {
kono
parents: 67
diff changeset
166 num_threads = gomp_resolve_num_threads (num_threads, 0);
kono
parents: 67
diff changeset
167 gomp_team_start (fn, data, num_threads, flags, gomp_new_team (num_threads));
kono
parents: 67
diff changeset
168 fn (data);
kono
parents: 67
diff changeset
169 ialias_call (GOMP_parallel_end) ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
111
kono
parents: 67
diff changeset
172 bool
kono
parents: 67
diff changeset
173 GOMP_cancellation_point (int which)
kono
parents: 67
diff changeset
174 {
kono
parents: 67
diff changeset
175 if (!gomp_cancel_var)
kono
parents: 67
diff changeset
176 return false;
kono
parents: 67
diff changeset
177
kono
parents: 67
diff changeset
178 struct gomp_thread *thr = gomp_thread ();
kono
parents: 67
diff changeset
179 struct gomp_team *team = thr->ts.team;
kono
parents: 67
diff changeset
180 if (which & (GOMP_CANCEL_LOOP | GOMP_CANCEL_SECTIONS))
kono
parents: 67
diff changeset
181 {
kono
parents: 67
diff changeset
182 if (team == NULL)
kono
parents: 67
diff changeset
183 return false;
kono
parents: 67
diff changeset
184 return team->work_share_cancelled != 0;
kono
parents: 67
diff changeset
185 }
kono
parents: 67
diff changeset
186 else if (which & GOMP_CANCEL_TASKGROUP)
kono
parents: 67
diff changeset
187 {
kono
parents: 67
diff changeset
188 if (thr->task->taskgroup && thr->task->taskgroup->cancelled)
kono
parents: 67
diff changeset
189 return true;
kono
parents: 67
diff changeset
190 /* FALLTHRU into the GOMP_CANCEL_PARALLEL case,
kono
parents: 67
diff changeset
191 as #pragma omp cancel parallel also cancels all explicit
kono
parents: 67
diff changeset
192 tasks. */
kono
parents: 67
diff changeset
193 }
kono
parents: 67
diff changeset
194 if (team)
kono
parents: 67
diff changeset
195 return gomp_team_barrier_cancelled (&team->barrier);
kono
parents: 67
diff changeset
196 return false;
kono
parents: 67
diff changeset
197 }
kono
parents: 67
diff changeset
198 ialias (GOMP_cancellation_point)
kono
parents: 67
diff changeset
199
kono
parents: 67
diff changeset
200 bool
kono
parents: 67
diff changeset
201 GOMP_cancel (int which, bool do_cancel)
kono
parents: 67
diff changeset
202 {
kono
parents: 67
diff changeset
203 if (!gomp_cancel_var)
kono
parents: 67
diff changeset
204 return false;
kono
parents: 67
diff changeset
205
kono
parents: 67
diff changeset
206 if (!do_cancel)
kono
parents: 67
diff changeset
207 return ialias_call (GOMP_cancellation_point) (which);
kono
parents: 67
diff changeset
208
kono
parents: 67
diff changeset
209 struct gomp_thread *thr = gomp_thread ();
kono
parents: 67
diff changeset
210 struct gomp_team *team = thr->ts.team;
kono
parents: 67
diff changeset
211 if (which & (GOMP_CANCEL_LOOP | GOMP_CANCEL_SECTIONS))
kono
parents: 67
diff changeset
212 {
kono
parents: 67
diff changeset
213 /* In orphaned worksharing region, all we want to cancel
kono
parents: 67
diff changeset
214 is current thread. */
kono
parents: 67
diff changeset
215 if (team != NULL)
kono
parents: 67
diff changeset
216 team->work_share_cancelled = 1;
kono
parents: 67
diff changeset
217 return true;
kono
parents: 67
diff changeset
218 }
kono
parents: 67
diff changeset
219 else if (which & GOMP_CANCEL_TASKGROUP)
kono
parents: 67
diff changeset
220 {
kono
parents: 67
diff changeset
221 if (thr->task->taskgroup && !thr->task->taskgroup->cancelled)
kono
parents: 67
diff changeset
222 {
kono
parents: 67
diff changeset
223 gomp_mutex_lock (&team->task_lock);
kono
parents: 67
diff changeset
224 thr->task->taskgroup->cancelled = true;
kono
parents: 67
diff changeset
225 gomp_mutex_unlock (&team->task_lock);
kono
parents: 67
diff changeset
226 }
kono
parents: 67
diff changeset
227 return true;
kono
parents: 67
diff changeset
228 }
kono
parents: 67
diff changeset
229 team->team_cancelled = 1;
kono
parents: 67
diff changeset
230 gomp_team_barrier_cancel (team);
kono
parents: 67
diff changeset
231 return true;
kono
parents: 67
diff changeset
232 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 /* The public OpenMP API for thread and team related inquiries. */
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 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 omp_get_num_threads (void)
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 struct gomp_team *team = gomp_thread ()->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 return team ? team->nthreads : 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 }
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 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 omp_get_thread_num (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 return gomp_thread ()->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 /* This wasn't right for OpenMP 2.5. Active region used to be non-zero
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 when the IF clause doesn't evaluate to false, starting with OpenMP 3.0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 it is non-zero with more than one thread in the team. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 omp_in_parallel (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 return gomp_thread ()->ts.active_level > 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 omp_get_level (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 return gomp_thread ()->ts.level;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 omp_get_ancestor_thread_num (int level)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 struct gomp_team_state *ts = &gomp_thread ()->ts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 if (level < 0 || level > ts->level)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 return -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 for (level = ts->level - level; level > 0; --level)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 ts = &ts->team->prev_ts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 return ts->team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 omp_get_team_size (int level)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 struct gomp_team_state *ts = &gomp_thread ()->ts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 if (level < 0 || level > ts->level)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 return -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 for (level = ts->level - level; level > 0; --level)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 ts = &ts->team->prev_ts;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 if (ts->team == NULL)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 return 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 return ts->team->nthreads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 omp_get_active_level (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 return gomp_thread ()->ts.active_level;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 ialias (omp_get_num_threads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 ialias (omp_get_thread_num)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 ialias (omp_in_parallel)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 ialias (omp_get_level)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 ialias (omp_get_ancestor_thread_num)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 ialias (omp_get_team_size)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 ialias (omp_get_active_level)