annotate libgomp/sections.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
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: 63
diff changeset
4 This file is part of the GNU Offloading and Multi Processing Library
kono
parents: 63
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 SECTIONS 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"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
29 #include <string.h>
0
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
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
32 ialias_redirect (GOMP_taskgroup_reduction_register)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
33
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 /* Initialize the given work share construct from the given arguments. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 gomp_sections_init (struct gomp_work_share *ws, unsigned count)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 ws->sched = GFS_DYNAMIC;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 ws->chunk_size = 1;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
41 ws->end = count + 1L;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 ws->incr = 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 ws->next = 1;
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
44 #ifdef HAVE_SYNC_BUILTINS
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
45 /* Prepare things to make each iteration faster. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
46 if (sizeof (long) > sizeof (unsigned))
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
47 ws->mode = 1;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
48 else
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
49 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
50 struct gomp_thread *thr = gomp_thread ();
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
51 struct gomp_team *team = thr->ts.team;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
52 long nthreads = team ? team->nthreads : 1;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
53
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
54 ws->mode = ((nthreads | ws->end)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
55 < 1UL << (sizeof (long) * __CHAR_BIT__ / 2 - 1));
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
56 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
57 #else
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
58 ws->mode = 0;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
59 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
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 /* This routine is called when first encountering a sections construct
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 that is not bound directly to a parallel construct. The first thread
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 that arrives will create the work-share construct; subsequent threads
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 will see the construct exists and allocate work from it.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 COUNT is the number of sections in this construct.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 Returns the 1-based section number for this thread to perform, or 0 if
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 all work was assigned to other threads prior to this thread's arrival. */
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 unsigned
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 GOMP_sections_start (unsigned count)
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 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 long s, e, ret;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
78 if (gomp_work_share_start (0))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 gomp_sections_init (thr->ts.work_share, count);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 gomp_work_share_init_done ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 #ifdef HAVE_SYNC_BUILTINS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 if (gomp_iter_dynamic_next (&s, &e))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 ret = s;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 ret = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 gomp_mutex_lock (&thr->ts.work_share->lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 if (gomp_iter_dynamic_next_locked (&s, &e))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 ret = s;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 ret = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 gomp_mutex_unlock (&thr->ts.work_share->lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 return ret;
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
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
101 unsigned
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
102 GOMP_sections2_start (unsigned count, uintptr_t *reductions, void **mem)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
103 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
104 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
105 long s, e, ret;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
106
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
107 if (reductions)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
108 gomp_workshare_taskgroup_start ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
109 if (gomp_work_share_start (0))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
110 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
111 gomp_sections_init (thr->ts.work_share, count);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
112 if (reductions)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
113 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
114 GOMP_taskgroup_reduction_register (reductions);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
115 thr->task->taskgroup->workshare = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
116 thr->ts.work_share->task_reductions = reductions;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
117 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
118 if (mem)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
119 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
120 uintptr_t size = (uintptr_t) *mem;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
121 #define INLINE_ORDERED_TEAM_IDS_OFF \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
122 ((offsetof (struct gomp_work_share, inline_ordered_team_ids) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
123 + __alignof__ (long long) - 1) & ~(__alignof__ (long long) - 1))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
124 if (size > (sizeof (struct gomp_work_share)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
125 - INLINE_ORDERED_TEAM_IDS_OFF))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
126 *mem
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
127 = (void *) (thr->ts.work_share->ordered_team_ids
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
128 = gomp_malloc_cleared (size));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
129 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
130 *mem = memset (((char *) thr->ts.work_share)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
131 + INLINE_ORDERED_TEAM_IDS_OFF, '\0', size);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
132 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
133 gomp_work_share_init_done ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
134 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
135 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
136 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
137 if (reductions)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
138 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
139 uintptr_t *first_reductions = thr->ts.work_share->task_reductions;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
140 gomp_workshare_task_reduction_register (reductions,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
141 first_reductions);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
142 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
143 if (mem)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
144 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
145 if ((offsetof (struct gomp_work_share, inline_ordered_team_ids)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
146 & (__alignof__ (long long) - 1)) == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
147 *mem = (void *) thr->ts.work_share->ordered_team_ids;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
148 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
149 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
150 uintptr_t p = (uintptr_t) thr->ts.work_share->ordered_team_ids;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
151 p += __alignof__ (long long) - 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
152 p &= ~(__alignof__ (long long) - 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
153 *mem = (void *) p;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
154 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
155 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
156 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
157
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
158 #ifdef HAVE_SYNC_BUILTINS
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
159 if (gomp_iter_dynamic_next (&s, &e))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
160 ret = s;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
161 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
162 ret = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
163 #else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
164 gomp_mutex_lock (&thr->ts.work_share->lock);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
165 if (gomp_iter_dynamic_next_locked (&s, &e))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
166 ret = s;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
167 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
168 ret = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
169 gomp_mutex_unlock (&thr->ts.work_share->lock);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
170 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
171
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
172 return ret;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
173 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
174
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 /* This routine is called when the thread completes processing of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 section currently assigned to it. If the work-share construct is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 bound directly to a parallel construct, then the construct may have
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 been set up before the parallel. In which case, this may be the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 first iteration for the thread.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 Returns the 1-based section number for this thread to perform, or 0 if
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 all work was assigned to other threads prior to this thread's arrival. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 unsigned
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 GOMP_sections_next (void)
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 long s, e, ret;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 #ifdef HAVE_SYNC_BUILTINS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 if (gomp_iter_dynamic_next (&s, &e))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 ret = s;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 ret = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 gomp_mutex_lock (&thr->ts.work_share->lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 if (gomp_iter_dynamic_next_locked (&s, &e))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 ret = s;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 ret = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 gomp_mutex_unlock (&thr->ts.work_share->lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 #endif
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 return ret;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 /* This routine pre-initializes a work-share construct to avoid one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 synchronization once we get into the loop. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 GOMP_parallel_sections_start (void (*fn) (void *), void *data,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 unsigned num_threads, unsigned count)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 struct gomp_team *team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 num_threads = gomp_resolve_num_threads (num_threads, count);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 team = gomp_new_team (num_threads);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 gomp_sections_init (&team->work_shares[0], count);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
220 gomp_team_start (fn, data, num_threads, 0, team, NULL);
111
kono
parents: 63
diff changeset
221 }
kono
parents: 63
diff changeset
222
kono
parents: 63
diff changeset
223 ialias_redirect (GOMP_parallel_end)
kono
parents: 63
diff changeset
224
kono
parents: 63
diff changeset
225 void
kono
parents: 63
diff changeset
226 GOMP_parallel_sections (void (*fn) (void *), void *data,
kono
parents: 63
diff changeset
227 unsigned num_threads, unsigned count, unsigned flags)
kono
parents: 63
diff changeset
228 {
kono
parents: 63
diff changeset
229 struct gomp_team *team;
kono
parents: 63
diff changeset
230
kono
parents: 63
diff changeset
231 num_threads = gomp_resolve_num_threads (num_threads, count);
kono
parents: 63
diff changeset
232 team = gomp_new_team (num_threads);
kono
parents: 63
diff changeset
233 gomp_sections_init (&team->work_shares[0], count);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
234 gomp_team_start (fn, data, num_threads, flags, team, NULL);
111
kono
parents: 63
diff changeset
235 fn (data);
kono
parents: 63
diff changeset
236 GOMP_parallel_end ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
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 /* The GOMP_section_end* routines are called after the thread is told
111
kono
parents: 63
diff changeset
240 that all sections are complete. The first two versions synchronize
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 all threads; the nowait version does not. */
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 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 GOMP_sections_end (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 gomp_work_share_end ();
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
111
kono
parents: 63
diff changeset
249 bool
kono
parents: 63
diff changeset
250 GOMP_sections_end_cancel (void)
kono
parents: 63
diff changeset
251 {
kono
parents: 63
diff changeset
252 return gomp_work_share_end_cancel ();
kono
parents: 63
diff changeset
253 }
kono
parents: 63
diff changeset
254
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 GOMP_sections_end_nowait (void)
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 gomp_work_share_end_nowait ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 }