annotate libgomp/ordered.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: 0
diff changeset
4 This file is part of the GNU Offloading and Multi Processing Library
kono
parents: 0
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 ORDERED 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"
111
kono
parents: 0
diff changeset
29 #include <stdarg.h>
kono
parents: 0
diff changeset
30 #include <string.h>
kono
parents: 0
diff changeset
31 #include "doacross.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 /* This function is called when first allocating an iteration block. That
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 is, the thread is not currently on the queue. The work-share lock must
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 be held on entry. */
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 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 gomp_ordered_first (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 unsigned index;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 /* Work share constructs can be orphaned. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 index = ws->ordered_cur + ws->ordered_num_used;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 if (index >= team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 index -= team->nthreads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 ws->ordered_team_ids[index] = thr->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 /* If this is the first and only thread in the queue, then there is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 no one to release us when we get to our ordered section. Post to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 our own release queue now so that we won't block later. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 if (ws->ordered_num_used++ == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 gomp_sem_post (team->ordered_release[thr->ts.team_id]);
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 function is called when completing the last iteration block. That
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 is, there are no more iterations to perform and so the thread should be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 removed from the queue entirely. Because of the way ORDERED blocks are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 managed, it follows that we currently own access to the ORDERED block,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 and should now pass it on to the next thread. The work-share lock must
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 be held on entry. */
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 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 gomp_ordered_last (void)
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 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 unsigned next_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 /* Work share constructs can be orphaned. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 /* We're no longer the owner. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 ws->ordered_owner = -1;
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 /* If we're not the last thread in the queue, then wake the next. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 if (--ws->ordered_num_used > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 unsigned next = ws->ordered_cur + 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 if (next == team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 next = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ws->ordered_cur = next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 next_id = ws->ordered_team_ids[next];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 gomp_sem_post (team->ordered_release[next_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 /* This function is called when allocating a subsequent allocation block.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 That is, we're done with the current iteration block and we're allocating
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 another. This is the logical combination of a call to gomp_ordered_last
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 followed by a call to gomp_ordered_first. The work-share lock must be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 held on entry. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 gomp_ordered_next (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 unsigned index, next_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
112 /* Work share constructs can be orphaned. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 /* We're no longer the owner. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 ws->ordered_owner = -1;
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 /* If there's only one thread in the queue, that must be us. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 if (ws->ordered_num_used == 1)
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 /* We have a similar situation as in gomp_ordered_first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 where we need to post to our own release semaphore. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 gomp_sem_post (team->ordered_release[thr->ts.team_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 }
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 /* If the queue is entirely full, then we move ourself to the end of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 the queue merely by incrementing ordered_cur. Only if it's not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 full do we have to write our id. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 if (ws->ordered_num_used < team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 index = ws->ordered_cur + ws->ordered_num_used;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 if (index >= team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 index -= team->nthreads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 ws->ordered_team_ids[index] = thr->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 index = ws->ordered_cur + 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 if (index == team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 index = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 ws->ordered_cur = index;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 next_id = ws->ordered_team_ids[index];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 gomp_sem_post (team->ordered_release[next_id]);
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 /* This function is called when a statically scheduled loop is first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 being created. */
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 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 gomp_ordered_static_init (void)
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 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 gomp_sem_post (team->ordered_release[0]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 /* This function is called when a statically scheduled loop is moving to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 the next allocation block. Static schedules are not first come first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 served like the others, so we're to move to the numerically next thread,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 not the next thread on a list. The work-share lock should *not* be held
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 on entry. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 gomp_ordered_static_next (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 unsigned id = thr->ts.team_id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 return;
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 ws->ordered_owner = -1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 /* This thread currently owns the lock. Increment the owner. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 if (++id == team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 id = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 ws->ordered_team_ids[0] = id;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 gomp_sem_post (team->ordered_release[id]);
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
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 /* This function is called when we need to assert that the thread owns the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 ordered section. Due to the problem of posted-but-not-waited semaphores,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 this needs to happen before completing a loop iteration. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 gomp_ordered_sync (void)
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 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 struct gomp_work_share *ws = thr->ts.work_share;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 /* Work share constructs can be orphaned. But this clearly means that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 we are the only thread, and so we automatically own the section. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 if (team == NULL || team->nthreads == 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 return;
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 /* ??? I believe it to be safe to access this data without taking the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 ws->lock. The only presumed race condition is with the previous
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 thread on the queue incrementing ordered_cur such that it points
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 to us, concurrently with our check below. But our team_id is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 already present in the queue, and the other thread will always
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 post to our release semaphore. So the two cases are that we will
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 either win the race an momentarily block on the semaphore, or lose
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 the race and find the semaphore already unlocked and so not block.
111
kono
parents: 0
diff changeset
214 Either way we get correct results.
kono
parents: 0
diff changeset
215 However, there is an implicit flush on entry to an ordered region,
kono
parents: 0
diff changeset
216 so we do need to have a barrier here. If we were taking a lock
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
217 this could be MEMMODEL_RELEASE since the acquire would be covered
111
kono
parents: 0
diff changeset
218 by the lock. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219
111
kono
parents: 0
diff changeset
220 __atomic_thread_fence (MEMMODEL_ACQ_REL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 if (ws->ordered_owner != thr->ts.team_id)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 gomp_sem_wait (team->ordered_release[thr->ts.team_id]);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 ws->ordered_owner = thr->ts.team_id;
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 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 /* This function is called by user code when encountering the start of an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 ORDERED block. We must check to see if the current thread is at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 head of the queue, and if not, block. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
231
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 #ifdef HAVE_ATTRIBUTE_ALIAS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 extern void GOMP_ordered_start (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 __attribute__((alias ("gomp_ordered_sync")));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 #else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 GOMP_ordered_start (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 gomp_ordered_sync ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 #endif
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 /* This function is called by user code when encountering the end of an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 ORDERED block. With the current ORDERED implementation there's nothing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 for us to do.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 However, the current implementation has a flaw in that it does not allow
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 the next thread into the ORDERED section immediately after the current
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
249 thread exits the ORDERED section in its last iteration. The existence
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 of this function allows the implementation to change. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 GOMP_ordered_end (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 }
111
kono
parents: 0
diff changeset
256
kono
parents: 0
diff changeset
257 /* DOACROSS initialization. */
kono
parents: 0
diff changeset
258
kono
parents: 0
diff changeset
259 #define MAX_COLLAPSED_BITS (__SIZEOF_LONG__ * __CHAR_BIT__)
kono
parents: 0
diff changeset
260
kono
parents: 0
diff changeset
261 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
262 gomp_doacross_init (unsigned ncounts, long *counts, long chunk_size,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
263 size_t extra)
111
kono
parents: 0
diff changeset
264 {
kono
parents: 0
diff changeset
265 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
266 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
267 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
268 unsigned int i, bits[MAX_COLLAPSED_BITS], num_bits = 0;
kono
parents: 0
diff changeset
269 unsigned long ent, num_ents, elt_sz, shift_sz;
kono
parents: 0
diff changeset
270 struct gomp_doacross_work_share *doacross;
kono
parents: 0
diff changeset
271
kono
parents: 0
diff changeset
272 if (team == NULL || team->nthreads == 1)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
273 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
274 empty:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
275 if (!extra)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
276 ws->doacross = NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
277 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
278 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
279 doacross = gomp_malloc_cleared (sizeof (*doacross) + extra);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
280 doacross->extra = (void *) (doacross + 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
281 ws->doacross = doacross;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
282 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
283 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
284 }
111
kono
parents: 0
diff changeset
285
kono
parents: 0
diff changeset
286 for (i = 0; i < ncounts; i++)
kono
parents: 0
diff changeset
287 {
kono
parents: 0
diff changeset
288 /* If any count is 0, GOMP_doacross_{post,wait} can't be called. */
kono
parents: 0
diff changeset
289 if (counts[i] == 0)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
290 goto empty;
111
kono
parents: 0
diff changeset
291
kono
parents: 0
diff changeset
292 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
293 {
kono
parents: 0
diff changeset
294 unsigned int this_bits;
kono
parents: 0
diff changeset
295 if (counts[i] == 1)
kono
parents: 0
diff changeset
296 this_bits = 1;
kono
parents: 0
diff changeset
297 else
kono
parents: 0
diff changeset
298 this_bits = __SIZEOF_LONG__ * __CHAR_BIT__
kono
parents: 0
diff changeset
299 - __builtin_clzl (counts[i] - 1);
kono
parents: 0
diff changeset
300 if (num_bits + this_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
301 {
kono
parents: 0
diff changeset
302 bits[i] = this_bits;
kono
parents: 0
diff changeset
303 num_bits += this_bits;
kono
parents: 0
diff changeset
304 }
kono
parents: 0
diff changeset
305 else
kono
parents: 0
diff changeset
306 num_bits = MAX_COLLAPSED_BITS + 1;
kono
parents: 0
diff changeset
307 }
kono
parents: 0
diff changeset
308 }
kono
parents: 0
diff changeset
309
kono
parents: 0
diff changeset
310 if (ws->sched == GFS_STATIC)
kono
parents: 0
diff changeset
311 num_ents = team->nthreads;
kono
parents: 0
diff changeset
312 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
313 num_ents = counts[0];
kono
parents: 0
diff changeset
314 else
kono
parents: 0
diff changeset
315 num_ents = (counts[0] - 1) / chunk_size + 1;
kono
parents: 0
diff changeset
316 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
317 {
kono
parents: 0
diff changeset
318 elt_sz = sizeof (unsigned long);
kono
parents: 0
diff changeset
319 shift_sz = ncounts * sizeof (unsigned int);
kono
parents: 0
diff changeset
320 }
kono
parents: 0
diff changeset
321 else
kono
parents: 0
diff changeset
322 {
kono
parents: 0
diff changeset
323 elt_sz = sizeof (unsigned long) * ncounts;
kono
parents: 0
diff changeset
324 shift_sz = 0;
kono
parents: 0
diff changeset
325 }
kono
parents: 0
diff changeset
326 elt_sz = (elt_sz + 63) & ~63UL;
kono
parents: 0
diff changeset
327
kono
parents: 0
diff changeset
328 doacross = gomp_malloc (sizeof (*doacross) + 63 + num_ents * elt_sz
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
329 + shift_sz + extra);
111
kono
parents: 0
diff changeset
330 doacross->chunk_size = chunk_size;
kono
parents: 0
diff changeset
331 doacross->elt_sz = elt_sz;
kono
parents: 0
diff changeset
332 doacross->ncounts = ncounts;
kono
parents: 0
diff changeset
333 doacross->flattened = false;
kono
parents: 0
diff changeset
334 doacross->array = (unsigned char *)
kono
parents: 0
diff changeset
335 ((((uintptr_t) (doacross + 1)) + 63 + shift_sz)
kono
parents: 0
diff changeset
336 & ~(uintptr_t) 63);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
337 if (extra)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
338 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
339 doacross->extra = doacross->array + num_ents * elt_sz;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
340 memset (doacross->extra, '\0', extra);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
341 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
342 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
343 doacross->extra = NULL;
111
kono
parents: 0
diff changeset
344 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
345 {
kono
parents: 0
diff changeset
346 unsigned int shift_count = 0;
kono
parents: 0
diff changeset
347 doacross->flattened = true;
kono
parents: 0
diff changeset
348 for (i = ncounts; i > 0; i--)
kono
parents: 0
diff changeset
349 {
kono
parents: 0
diff changeset
350 doacross->shift_counts[i - 1] = shift_count;
kono
parents: 0
diff changeset
351 shift_count += bits[i - 1];
kono
parents: 0
diff changeset
352 }
kono
parents: 0
diff changeset
353 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
354 *(unsigned long *) (doacross->array + ent * elt_sz) = 0;
kono
parents: 0
diff changeset
355 }
kono
parents: 0
diff changeset
356 else
kono
parents: 0
diff changeset
357 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
358 memset (doacross->array + ent * elt_sz, '\0',
kono
parents: 0
diff changeset
359 sizeof (unsigned long) * ncounts);
kono
parents: 0
diff changeset
360 if (ws->sched == GFS_STATIC && chunk_size == 0)
kono
parents: 0
diff changeset
361 {
kono
parents: 0
diff changeset
362 unsigned long q = counts[0] / num_ents;
kono
parents: 0
diff changeset
363 unsigned long t = counts[0] % num_ents;
kono
parents: 0
diff changeset
364 doacross->boundary = t * (q + 1);
kono
parents: 0
diff changeset
365 doacross->q = q;
kono
parents: 0
diff changeset
366 doacross->t = t;
kono
parents: 0
diff changeset
367 }
kono
parents: 0
diff changeset
368 ws->doacross = doacross;
kono
parents: 0
diff changeset
369 }
kono
parents: 0
diff changeset
370
kono
parents: 0
diff changeset
371 /* DOACROSS POST operation. */
kono
parents: 0
diff changeset
372
kono
parents: 0
diff changeset
373 void
kono
parents: 0
diff changeset
374 GOMP_doacross_post (long *counts)
kono
parents: 0
diff changeset
375 {
kono
parents: 0
diff changeset
376 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
377 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
378 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
379 unsigned long ent;
kono
parents: 0
diff changeset
380 unsigned int i;
kono
parents: 0
diff changeset
381
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
382 if (__builtin_expect (doacross == NULL, 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
383 || __builtin_expect (doacross->array == NULL, 0))
111
kono
parents: 0
diff changeset
384 {
kono
parents: 0
diff changeset
385 __sync_synchronize ();
kono
parents: 0
diff changeset
386 return;
kono
parents: 0
diff changeset
387 }
kono
parents: 0
diff changeset
388
kono
parents: 0
diff changeset
389 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
390 ent = thr->ts.team_id;
kono
parents: 0
diff changeset
391 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
392 ent = counts[0];
kono
parents: 0
diff changeset
393 else
kono
parents: 0
diff changeset
394 ent = counts[0] / doacross->chunk_size;
kono
parents: 0
diff changeset
395 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
396 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
397
kono
parents: 0
diff changeset
398 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
399 {
kono
parents: 0
diff changeset
400 unsigned long flattened
kono
parents: 0
diff changeset
401 = (unsigned long) counts[0] << doacross->shift_counts[0];
kono
parents: 0
diff changeset
402
kono
parents: 0
diff changeset
403 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
404 flattened |= (unsigned long) counts[i]
kono
parents: 0
diff changeset
405 << doacross->shift_counts[i];
kono
parents: 0
diff changeset
406 flattened++;
kono
parents: 0
diff changeset
407 if (flattened == __atomic_load_n (array, MEMMODEL_ACQUIRE))
kono
parents: 0
diff changeset
408 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
409 else
kono
parents: 0
diff changeset
410 __atomic_store_n (array, flattened, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
411 return;
kono
parents: 0
diff changeset
412 }
kono
parents: 0
diff changeset
413
kono
parents: 0
diff changeset
414 __atomic_thread_fence (MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
415 for (i = doacross->ncounts; i-- > 0; )
kono
parents: 0
diff changeset
416 {
kono
parents: 0
diff changeset
417 if (counts[i] + 1UL != __atomic_load_n (&array[i], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
418 __atomic_store_n (&array[i], counts[i] + 1UL, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
419 }
kono
parents: 0
diff changeset
420 }
kono
parents: 0
diff changeset
421
kono
parents: 0
diff changeset
422 /* DOACROSS WAIT operation. */
kono
parents: 0
diff changeset
423
kono
parents: 0
diff changeset
424 void
kono
parents: 0
diff changeset
425 GOMP_doacross_wait (long first, ...)
kono
parents: 0
diff changeset
426 {
kono
parents: 0
diff changeset
427 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
428 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
429 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
430 va_list ap;
kono
parents: 0
diff changeset
431 unsigned long ent;
kono
parents: 0
diff changeset
432 unsigned int i;
kono
parents: 0
diff changeset
433
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
434 if (__builtin_expect (doacross == NULL, 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
435 || __builtin_expect (doacross->array == NULL, 0))
111
kono
parents: 0
diff changeset
436 {
kono
parents: 0
diff changeset
437 __sync_synchronize ();
kono
parents: 0
diff changeset
438 return;
kono
parents: 0
diff changeset
439 }
kono
parents: 0
diff changeset
440
kono
parents: 0
diff changeset
441 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
442 {
kono
parents: 0
diff changeset
443 if (ws->chunk_size == 0)
kono
parents: 0
diff changeset
444 {
kono
parents: 0
diff changeset
445 if (first < doacross->boundary)
kono
parents: 0
diff changeset
446 ent = first / (doacross->q + 1);
kono
parents: 0
diff changeset
447 else
kono
parents: 0
diff changeset
448 ent = (first - doacross->boundary) / doacross->q
kono
parents: 0
diff changeset
449 + doacross->t;
kono
parents: 0
diff changeset
450 }
kono
parents: 0
diff changeset
451 else
kono
parents: 0
diff changeset
452 ent = first / ws->chunk_size % thr->ts.team->nthreads;
kono
parents: 0
diff changeset
453 }
kono
parents: 0
diff changeset
454 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
455 ent = first;
kono
parents: 0
diff changeset
456 else
kono
parents: 0
diff changeset
457 ent = first / doacross->chunk_size;
kono
parents: 0
diff changeset
458 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
459 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
460
kono
parents: 0
diff changeset
461 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
462 {
kono
parents: 0
diff changeset
463 unsigned long flattened
kono
parents: 0
diff changeset
464 = (unsigned long) first << doacross->shift_counts[0];
kono
parents: 0
diff changeset
465 unsigned long cur;
kono
parents: 0
diff changeset
466
kono
parents: 0
diff changeset
467 va_start (ap, first);
kono
parents: 0
diff changeset
468 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
469 flattened |= (unsigned long) va_arg (ap, long)
kono
parents: 0
diff changeset
470 << doacross->shift_counts[i];
kono
parents: 0
diff changeset
471 cur = __atomic_load_n (array, MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
472 if (flattened < cur)
kono
parents: 0
diff changeset
473 {
kono
parents: 0
diff changeset
474 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
475 va_end (ap);
kono
parents: 0
diff changeset
476 return;
kono
parents: 0
diff changeset
477 }
kono
parents: 0
diff changeset
478 doacross_spin (array, flattened, cur);
kono
parents: 0
diff changeset
479 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
480 va_end (ap);
kono
parents: 0
diff changeset
481 return;
kono
parents: 0
diff changeset
482 }
kono
parents: 0
diff changeset
483
kono
parents: 0
diff changeset
484 do
kono
parents: 0
diff changeset
485 {
kono
parents: 0
diff changeset
486 va_start (ap, first);
kono
parents: 0
diff changeset
487 for (i = 0; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
488 {
kono
parents: 0
diff changeset
489 unsigned long thisv
kono
parents: 0
diff changeset
490 = (unsigned long) (i ? va_arg (ap, long) : first) + 1;
kono
parents: 0
diff changeset
491 unsigned long cur = __atomic_load_n (&array[i], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
492 if (thisv < cur)
kono
parents: 0
diff changeset
493 {
kono
parents: 0
diff changeset
494 i = doacross->ncounts;
kono
parents: 0
diff changeset
495 break;
kono
parents: 0
diff changeset
496 }
kono
parents: 0
diff changeset
497 if (thisv > cur)
kono
parents: 0
diff changeset
498 break;
kono
parents: 0
diff changeset
499 }
kono
parents: 0
diff changeset
500 va_end (ap);
kono
parents: 0
diff changeset
501 if (i == doacross->ncounts)
kono
parents: 0
diff changeset
502 break;
kono
parents: 0
diff changeset
503 cpu_relax ();
kono
parents: 0
diff changeset
504 }
kono
parents: 0
diff changeset
505 while (1);
kono
parents: 0
diff changeset
506 __sync_synchronize ();
kono
parents: 0
diff changeset
507 }
kono
parents: 0
diff changeset
508
kono
parents: 0
diff changeset
509 typedef unsigned long long gomp_ull;
kono
parents: 0
diff changeset
510
kono
parents: 0
diff changeset
511 void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
512 gomp_doacross_ull_init (unsigned ncounts, gomp_ull *counts,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
513 gomp_ull chunk_size, size_t extra)
111
kono
parents: 0
diff changeset
514 {
kono
parents: 0
diff changeset
515 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
516 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
517 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
518 unsigned int i, bits[MAX_COLLAPSED_BITS], num_bits = 0;
kono
parents: 0
diff changeset
519 unsigned long ent, num_ents, elt_sz, shift_sz;
kono
parents: 0
diff changeset
520 struct gomp_doacross_work_share *doacross;
kono
parents: 0
diff changeset
521
kono
parents: 0
diff changeset
522 if (team == NULL || team->nthreads == 1)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
523 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
524 empty:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
525 if (!extra)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
526 ws->doacross = NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
527 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
528 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
529 doacross = gomp_malloc_cleared (sizeof (*doacross) + extra);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
530 doacross->extra = (void *) (doacross + 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
531 ws->doacross = doacross;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
532 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
533 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
534 }
111
kono
parents: 0
diff changeset
535
kono
parents: 0
diff changeset
536 for (i = 0; i < ncounts; i++)
kono
parents: 0
diff changeset
537 {
kono
parents: 0
diff changeset
538 /* If any count is 0, GOMP_doacross_{post,wait} can't be called. */
kono
parents: 0
diff changeset
539 if (counts[i] == 0)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
540 goto empty;
111
kono
parents: 0
diff changeset
541
kono
parents: 0
diff changeset
542 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
543 {
kono
parents: 0
diff changeset
544 unsigned int this_bits;
kono
parents: 0
diff changeset
545 if (counts[i] == 1)
kono
parents: 0
diff changeset
546 this_bits = 1;
kono
parents: 0
diff changeset
547 else
kono
parents: 0
diff changeset
548 this_bits = __SIZEOF_LONG_LONG__ * __CHAR_BIT__
kono
parents: 0
diff changeset
549 - __builtin_clzll (counts[i] - 1);
kono
parents: 0
diff changeset
550 if (num_bits + this_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
551 {
kono
parents: 0
diff changeset
552 bits[i] = this_bits;
kono
parents: 0
diff changeset
553 num_bits += this_bits;
kono
parents: 0
diff changeset
554 }
kono
parents: 0
diff changeset
555 else
kono
parents: 0
diff changeset
556 num_bits = MAX_COLLAPSED_BITS + 1;
kono
parents: 0
diff changeset
557 }
kono
parents: 0
diff changeset
558 }
kono
parents: 0
diff changeset
559
kono
parents: 0
diff changeset
560 if (ws->sched == GFS_STATIC)
kono
parents: 0
diff changeset
561 num_ents = team->nthreads;
kono
parents: 0
diff changeset
562 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
563 num_ents = counts[0];
kono
parents: 0
diff changeset
564 else
kono
parents: 0
diff changeset
565 num_ents = (counts[0] - 1) / chunk_size + 1;
kono
parents: 0
diff changeset
566 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
567 {
kono
parents: 0
diff changeset
568 elt_sz = sizeof (unsigned long);
kono
parents: 0
diff changeset
569 shift_sz = ncounts * sizeof (unsigned int);
kono
parents: 0
diff changeset
570 }
kono
parents: 0
diff changeset
571 else
kono
parents: 0
diff changeset
572 {
kono
parents: 0
diff changeset
573 if (sizeof (gomp_ull) == sizeof (unsigned long))
kono
parents: 0
diff changeset
574 elt_sz = sizeof (gomp_ull) * ncounts;
kono
parents: 0
diff changeset
575 else if (sizeof (gomp_ull) == 2 * sizeof (unsigned long))
kono
parents: 0
diff changeset
576 elt_sz = sizeof (unsigned long) * 2 * ncounts;
kono
parents: 0
diff changeset
577 else
kono
parents: 0
diff changeset
578 abort ();
kono
parents: 0
diff changeset
579 shift_sz = 0;
kono
parents: 0
diff changeset
580 }
kono
parents: 0
diff changeset
581 elt_sz = (elt_sz + 63) & ~63UL;
kono
parents: 0
diff changeset
582
kono
parents: 0
diff changeset
583 doacross = gomp_malloc (sizeof (*doacross) + 63 + num_ents * elt_sz
kono
parents: 0
diff changeset
584 + shift_sz);
kono
parents: 0
diff changeset
585 doacross->chunk_size_ull = chunk_size;
kono
parents: 0
diff changeset
586 doacross->elt_sz = elt_sz;
kono
parents: 0
diff changeset
587 doacross->ncounts = ncounts;
kono
parents: 0
diff changeset
588 doacross->flattened = false;
kono
parents: 0
diff changeset
589 doacross->boundary = 0;
kono
parents: 0
diff changeset
590 doacross->array = (unsigned char *)
kono
parents: 0
diff changeset
591 ((((uintptr_t) (doacross + 1)) + 63 + shift_sz)
kono
parents: 0
diff changeset
592 & ~(uintptr_t) 63);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
593 if (extra)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
594 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
595 doacross->extra = doacross->array + num_ents * elt_sz;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
596 memset (doacross->extra, '\0', extra);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
597 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
598 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
599 doacross->extra = NULL;
111
kono
parents: 0
diff changeset
600 if (num_bits <= MAX_COLLAPSED_BITS)
kono
parents: 0
diff changeset
601 {
kono
parents: 0
diff changeset
602 unsigned int shift_count = 0;
kono
parents: 0
diff changeset
603 doacross->flattened = true;
kono
parents: 0
diff changeset
604 for (i = ncounts; i > 0; i--)
kono
parents: 0
diff changeset
605 {
kono
parents: 0
diff changeset
606 doacross->shift_counts[i - 1] = shift_count;
kono
parents: 0
diff changeset
607 shift_count += bits[i - 1];
kono
parents: 0
diff changeset
608 }
kono
parents: 0
diff changeset
609 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
610 *(unsigned long *) (doacross->array + ent * elt_sz) = 0;
kono
parents: 0
diff changeset
611 }
kono
parents: 0
diff changeset
612 else
kono
parents: 0
diff changeset
613 for (ent = 0; ent < num_ents; ent++)
kono
parents: 0
diff changeset
614 memset (doacross->array + ent * elt_sz, '\0',
kono
parents: 0
diff changeset
615 sizeof (unsigned long) * ncounts);
kono
parents: 0
diff changeset
616 if (ws->sched == GFS_STATIC && chunk_size == 0)
kono
parents: 0
diff changeset
617 {
kono
parents: 0
diff changeset
618 gomp_ull q = counts[0] / num_ents;
kono
parents: 0
diff changeset
619 gomp_ull t = counts[0] % num_ents;
kono
parents: 0
diff changeset
620 doacross->boundary_ull = t * (q + 1);
kono
parents: 0
diff changeset
621 doacross->q_ull = q;
kono
parents: 0
diff changeset
622 doacross->t = t;
kono
parents: 0
diff changeset
623 }
kono
parents: 0
diff changeset
624 ws->doacross = doacross;
kono
parents: 0
diff changeset
625 }
kono
parents: 0
diff changeset
626
kono
parents: 0
diff changeset
627 /* DOACROSS POST operation. */
kono
parents: 0
diff changeset
628
kono
parents: 0
diff changeset
629 void
kono
parents: 0
diff changeset
630 GOMP_doacross_ull_post (gomp_ull *counts)
kono
parents: 0
diff changeset
631 {
kono
parents: 0
diff changeset
632 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
633 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
634 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
635 unsigned long ent;
kono
parents: 0
diff changeset
636 unsigned int i;
kono
parents: 0
diff changeset
637
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
638 if (__builtin_expect (doacross == NULL, 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
639 || __builtin_expect (doacross->array == NULL, 0))
111
kono
parents: 0
diff changeset
640 {
kono
parents: 0
diff changeset
641 __sync_synchronize ();
kono
parents: 0
diff changeset
642 return;
kono
parents: 0
diff changeset
643 }
kono
parents: 0
diff changeset
644
kono
parents: 0
diff changeset
645 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
646 ent = thr->ts.team_id;
kono
parents: 0
diff changeset
647 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
648 ent = counts[0];
kono
parents: 0
diff changeset
649 else
kono
parents: 0
diff changeset
650 ent = counts[0] / doacross->chunk_size_ull;
kono
parents: 0
diff changeset
651
kono
parents: 0
diff changeset
652 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
653 {
kono
parents: 0
diff changeset
654 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
655 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
656 gomp_ull flattened
kono
parents: 0
diff changeset
657 = counts[0] << doacross->shift_counts[0];
kono
parents: 0
diff changeset
658
kono
parents: 0
diff changeset
659 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
660 flattened |= counts[i] << doacross->shift_counts[i];
kono
parents: 0
diff changeset
661 flattened++;
kono
parents: 0
diff changeset
662 if (flattened == __atomic_load_n (array, MEMMODEL_ACQUIRE))
kono
parents: 0
diff changeset
663 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
664 else
kono
parents: 0
diff changeset
665 __atomic_store_n (array, flattened, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
666 return;
kono
parents: 0
diff changeset
667 }
kono
parents: 0
diff changeset
668
kono
parents: 0
diff changeset
669 __atomic_thread_fence (MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
670 if (sizeof (gomp_ull) == sizeof (unsigned long))
kono
parents: 0
diff changeset
671 {
kono
parents: 0
diff changeset
672 gomp_ull *array = (gomp_ull *) (doacross->array
kono
parents: 0
diff changeset
673 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
674
kono
parents: 0
diff changeset
675 for (i = doacross->ncounts; i-- > 0; )
kono
parents: 0
diff changeset
676 {
kono
parents: 0
diff changeset
677 if (counts[i] + 1UL != __atomic_load_n (&array[i], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
678 __atomic_store_n (&array[i], counts[i] + 1UL, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
679 }
kono
parents: 0
diff changeset
680 }
kono
parents: 0
diff changeset
681 else
kono
parents: 0
diff changeset
682 {
kono
parents: 0
diff changeset
683 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
684 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
685
kono
parents: 0
diff changeset
686 for (i = doacross->ncounts; i-- > 0; )
kono
parents: 0
diff changeset
687 {
kono
parents: 0
diff changeset
688 gomp_ull cull = counts[i] + 1UL;
kono
parents: 0
diff changeset
689 unsigned long c = (unsigned long) cull;
kono
parents: 0
diff changeset
690 if (c != __atomic_load_n (&array[2 * i + 1], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
691 __atomic_store_n (&array[2 * i + 1], c, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
692 c = cull >> (__SIZEOF_LONG_LONG__ * __CHAR_BIT__ / 2);
kono
parents: 0
diff changeset
693 if (c != __atomic_load_n (&array[2 * i], MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
694 __atomic_store_n (&array[2 * i], c, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
695 }
kono
parents: 0
diff changeset
696 }
kono
parents: 0
diff changeset
697 }
kono
parents: 0
diff changeset
698
kono
parents: 0
diff changeset
699 /* DOACROSS WAIT operation. */
kono
parents: 0
diff changeset
700
kono
parents: 0
diff changeset
701 void
kono
parents: 0
diff changeset
702 GOMP_doacross_ull_wait (gomp_ull first, ...)
kono
parents: 0
diff changeset
703 {
kono
parents: 0
diff changeset
704 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
705 struct gomp_work_share *ws = thr->ts.work_share;
kono
parents: 0
diff changeset
706 struct gomp_doacross_work_share *doacross = ws->doacross;
kono
parents: 0
diff changeset
707 va_list ap;
kono
parents: 0
diff changeset
708 unsigned long ent;
kono
parents: 0
diff changeset
709 unsigned int i;
kono
parents: 0
diff changeset
710
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
711 if (__builtin_expect (doacross == NULL, 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
712 || __builtin_expect (doacross->array == NULL, 0))
111
kono
parents: 0
diff changeset
713 {
kono
parents: 0
diff changeset
714 __sync_synchronize ();
kono
parents: 0
diff changeset
715 return;
kono
parents: 0
diff changeset
716 }
kono
parents: 0
diff changeset
717
kono
parents: 0
diff changeset
718 if (__builtin_expect (ws->sched == GFS_STATIC, 1))
kono
parents: 0
diff changeset
719 {
kono
parents: 0
diff changeset
720 if (ws->chunk_size_ull == 0)
kono
parents: 0
diff changeset
721 {
kono
parents: 0
diff changeset
722 if (first < doacross->boundary_ull)
kono
parents: 0
diff changeset
723 ent = first / (doacross->q_ull + 1);
kono
parents: 0
diff changeset
724 else
kono
parents: 0
diff changeset
725 ent = (first - doacross->boundary_ull) / doacross->q_ull
kono
parents: 0
diff changeset
726 + doacross->t;
kono
parents: 0
diff changeset
727 }
kono
parents: 0
diff changeset
728 else
kono
parents: 0
diff changeset
729 ent = first / ws->chunk_size_ull % thr->ts.team->nthreads;
kono
parents: 0
diff changeset
730 }
kono
parents: 0
diff changeset
731 else if (ws->sched == GFS_GUIDED)
kono
parents: 0
diff changeset
732 ent = first;
kono
parents: 0
diff changeset
733 else
kono
parents: 0
diff changeset
734 ent = first / doacross->chunk_size_ull;
kono
parents: 0
diff changeset
735
kono
parents: 0
diff changeset
736 if (__builtin_expect (doacross->flattened, 1))
kono
parents: 0
diff changeset
737 {
kono
parents: 0
diff changeset
738 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
739 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
740 gomp_ull flattened = first << doacross->shift_counts[0];
kono
parents: 0
diff changeset
741 unsigned long cur;
kono
parents: 0
diff changeset
742
kono
parents: 0
diff changeset
743 va_start (ap, first);
kono
parents: 0
diff changeset
744 for (i = 1; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
745 flattened |= va_arg (ap, gomp_ull)
kono
parents: 0
diff changeset
746 << doacross->shift_counts[i];
kono
parents: 0
diff changeset
747 cur = __atomic_load_n (array, MEMMODEL_ACQUIRE);
kono
parents: 0
diff changeset
748 if (flattened < cur)
kono
parents: 0
diff changeset
749 {
kono
parents: 0
diff changeset
750 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
751 va_end (ap);
kono
parents: 0
diff changeset
752 return;
kono
parents: 0
diff changeset
753 }
kono
parents: 0
diff changeset
754 doacross_spin (array, flattened, cur);
kono
parents: 0
diff changeset
755 __atomic_thread_fence (MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
756 va_end (ap);
kono
parents: 0
diff changeset
757 return;
kono
parents: 0
diff changeset
758 }
kono
parents: 0
diff changeset
759
kono
parents: 0
diff changeset
760 if (sizeof (gomp_ull) == sizeof (unsigned long))
kono
parents: 0
diff changeset
761 {
kono
parents: 0
diff changeset
762 gomp_ull *array = (gomp_ull *) (doacross->array
kono
parents: 0
diff changeset
763 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
764 do
kono
parents: 0
diff changeset
765 {
kono
parents: 0
diff changeset
766 va_start (ap, first);
kono
parents: 0
diff changeset
767 for (i = 0; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
768 {
kono
parents: 0
diff changeset
769 gomp_ull thisv
kono
parents: 0
diff changeset
770 = (i ? va_arg (ap, gomp_ull) : first) + 1;
kono
parents: 0
diff changeset
771 gomp_ull cur = __atomic_load_n (&array[i], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
772 if (thisv < cur)
kono
parents: 0
diff changeset
773 {
kono
parents: 0
diff changeset
774 i = doacross->ncounts;
kono
parents: 0
diff changeset
775 break;
kono
parents: 0
diff changeset
776 }
kono
parents: 0
diff changeset
777 if (thisv > cur)
kono
parents: 0
diff changeset
778 break;
kono
parents: 0
diff changeset
779 }
kono
parents: 0
diff changeset
780 va_end (ap);
kono
parents: 0
diff changeset
781 if (i == doacross->ncounts)
kono
parents: 0
diff changeset
782 break;
kono
parents: 0
diff changeset
783 cpu_relax ();
kono
parents: 0
diff changeset
784 }
kono
parents: 0
diff changeset
785 while (1);
kono
parents: 0
diff changeset
786 }
kono
parents: 0
diff changeset
787 else
kono
parents: 0
diff changeset
788 {
kono
parents: 0
diff changeset
789 unsigned long *array = (unsigned long *) (doacross->array
kono
parents: 0
diff changeset
790 + ent * doacross->elt_sz);
kono
parents: 0
diff changeset
791 do
kono
parents: 0
diff changeset
792 {
kono
parents: 0
diff changeset
793 va_start (ap, first);
kono
parents: 0
diff changeset
794 for (i = 0; i < doacross->ncounts; i++)
kono
parents: 0
diff changeset
795 {
kono
parents: 0
diff changeset
796 gomp_ull thisv
kono
parents: 0
diff changeset
797 = (i ? va_arg (ap, gomp_ull) : first) + 1;
kono
parents: 0
diff changeset
798 unsigned long t
kono
parents: 0
diff changeset
799 = thisv >> (__SIZEOF_LONG_LONG__ * __CHAR_BIT__ / 2);
kono
parents: 0
diff changeset
800 unsigned long cur
kono
parents: 0
diff changeset
801 = __atomic_load_n (&array[2 * i], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
802 if (t < cur)
kono
parents: 0
diff changeset
803 {
kono
parents: 0
diff changeset
804 i = doacross->ncounts;
kono
parents: 0
diff changeset
805 break;
kono
parents: 0
diff changeset
806 }
kono
parents: 0
diff changeset
807 if (t > cur)
kono
parents: 0
diff changeset
808 break;
kono
parents: 0
diff changeset
809 t = thisv;
kono
parents: 0
diff changeset
810 cur = __atomic_load_n (&array[2 * i + 1], MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
811 if (t < cur)
kono
parents: 0
diff changeset
812 {
kono
parents: 0
diff changeset
813 i = doacross->ncounts;
kono
parents: 0
diff changeset
814 break;
kono
parents: 0
diff changeset
815 }
kono
parents: 0
diff changeset
816 if (t > cur)
kono
parents: 0
diff changeset
817 break;
kono
parents: 0
diff changeset
818 }
kono
parents: 0
diff changeset
819 va_end (ap);
kono
parents: 0
diff changeset
820 if (i == doacross->ncounts)
kono
parents: 0
diff changeset
821 break;
kono
parents: 0
diff changeset
822 cpu_relax ();
kono
parents: 0
diff changeset
823 }
kono
parents: 0
diff changeset
824 while (1);
kono
parents: 0
diff changeset
825 }
kono
parents: 0
diff changeset
826 __sync_synchronize ();
kono
parents: 0
diff changeset
827 }