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

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1 /* Copyright (C) 2007-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
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
26 /* This file handles the maintenance of tasks in response to task
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 creation and termination. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include "libgomp.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #include <stdlib.h>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 #include <string.h>
111
kono
parents: 0
diff changeset
32 #include "gomp-constants.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
111
kono
parents: 0
diff changeset
34 typedef struct gomp_task_depend_entry *hash_entry_type;
kono
parents: 0
diff changeset
35
kono
parents: 0
diff changeset
36 static inline void *
kono
parents: 0
diff changeset
37 htab_alloc (size_t size)
kono
parents: 0
diff changeset
38 {
kono
parents: 0
diff changeset
39 return gomp_malloc (size);
kono
parents: 0
diff changeset
40 }
kono
parents: 0
diff changeset
41
kono
parents: 0
diff changeset
42 static inline void
kono
parents: 0
diff changeset
43 htab_free (void *ptr)
kono
parents: 0
diff changeset
44 {
kono
parents: 0
diff changeset
45 free (ptr);
kono
parents: 0
diff changeset
46 }
kono
parents: 0
diff changeset
47
kono
parents: 0
diff changeset
48 #include "hashtab.h"
kono
parents: 0
diff changeset
49
kono
parents: 0
diff changeset
50 static inline hashval_t
kono
parents: 0
diff changeset
51 htab_hash (hash_entry_type element)
kono
parents: 0
diff changeset
52 {
kono
parents: 0
diff changeset
53 return hash_pointer (element->addr);
kono
parents: 0
diff changeset
54 }
kono
parents: 0
diff changeset
55
kono
parents: 0
diff changeset
56 static inline bool
kono
parents: 0
diff changeset
57 htab_eq (hash_entry_type x, hash_entry_type y)
kono
parents: 0
diff changeset
58 {
kono
parents: 0
diff changeset
59 return x->addr == y->addr;
kono
parents: 0
diff changeset
60 }
0
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 /* Create a new task data structure. */
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 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 gomp_init_task (struct gomp_task *task, struct gomp_task *parent_task,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 struct gomp_task_icv *prev_icv)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 {
111
kono
parents: 0
diff changeset
68 /* It would seem that using memset here would be a win, but it turns
kono
parents: 0
diff changeset
69 out that partially filling gomp_task allows us to keep the
kono
parents: 0
diff changeset
70 overhead of task creation low. In the nqueens-1.c test, for a
kono
parents: 0
diff changeset
71 sufficiently large N, we drop the overhead from 5-6% to 1%.
kono
parents: 0
diff changeset
72
kono
parents: 0
diff changeset
73 Note, the nqueens-1.c test in serial mode is a good test to
kono
parents: 0
diff changeset
74 benchmark the overhead of creating tasks as there are millions of
kono
parents: 0
diff changeset
75 tiny tasks created that all run undeferred. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 task->parent = parent_task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 task->icv = *prev_icv;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 task->kind = GOMP_TASK_IMPLICIT;
111
kono
parents: 0
diff changeset
79 task->taskwait = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 task->in_tied_task = false;
111
kono
parents: 0
diff changeset
81 task->final_task = false;
kono
parents: 0
diff changeset
82 task->copy_ctors_done = false;
kono
parents: 0
diff changeset
83 task->parent_depends_on = false;
kono
parents: 0
diff changeset
84 priority_queue_init (&task->children_queue);
kono
parents: 0
diff changeset
85 task->taskgroup = NULL;
kono
parents: 0
diff changeset
86 task->dependers = NULL;
kono
parents: 0
diff changeset
87 task->depend_hash = NULL;
kono
parents: 0
diff changeset
88 task->depend_count = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 /* Clean up a task, after completing it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 gomp_end_task (void)
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 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 struct gomp_task *task = thr->task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 gomp_finish_task (task);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 thr->task = task->parent;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
111
kono
parents: 0
diff changeset
103 /* Clear the parent field of every task in LIST. */
kono
parents: 0
diff changeset
104
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105 static inline void
111
kono
parents: 0
diff changeset
106 gomp_clear_parent_in_list (struct priority_list *list)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 {
111
kono
parents: 0
diff changeset
108 struct priority_node *p = list->tasks;
kono
parents: 0
diff changeset
109 if (p)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 {
111
kono
parents: 0
diff changeset
112 priority_node_to_task (PQ_CHILDREN, p)->parent = NULL;
kono
parents: 0
diff changeset
113 p = p->next;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 }
111
kono
parents: 0
diff changeset
115 while (p != list->tasks);
kono
parents: 0
diff changeset
116 }
kono
parents: 0
diff changeset
117
kono
parents: 0
diff changeset
118 /* Splay tree version of gomp_clear_parent_in_list.
kono
parents: 0
diff changeset
119
kono
parents: 0
diff changeset
120 Clear the parent field of every task in NODE within SP, and free
kono
parents: 0
diff changeset
121 the node when done. */
kono
parents: 0
diff changeset
122
kono
parents: 0
diff changeset
123 static void
kono
parents: 0
diff changeset
124 gomp_clear_parent_in_tree (prio_splay_tree sp, prio_splay_tree_node node)
kono
parents: 0
diff changeset
125 {
kono
parents: 0
diff changeset
126 if (!node)
kono
parents: 0
diff changeset
127 return;
kono
parents: 0
diff changeset
128 prio_splay_tree_node left = node->left, right = node->right;
kono
parents: 0
diff changeset
129 gomp_clear_parent_in_list (&node->key.l);
kono
parents: 0
diff changeset
130 #if _LIBGOMP_CHECKING_
kono
parents: 0
diff changeset
131 memset (node, 0xaf, sizeof (*node));
kono
parents: 0
diff changeset
132 #endif
kono
parents: 0
diff changeset
133 /* No need to remove the node from the tree. We're nuking
kono
parents: 0
diff changeset
134 everything, so just free the nodes and our caller can clear the
kono
parents: 0
diff changeset
135 entire splay tree. */
kono
parents: 0
diff changeset
136 free (node);
kono
parents: 0
diff changeset
137 gomp_clear_parent_in_tree (sp, left);
kono
parents: 0
diff changeset
138 gomp_clear_parent_in_tree (sp, right);
kono
parents: 0
diff changeset
139 }
kono
parents: 0
diff changeset
140
kono
parents: 0
diff changeset
141 /* Clear the parent field of every task in Q and remove every task
kono
parents: 0
diff changeset
142 from Q. */
kono
parents: 0
diff changeset
143
kono
parents: 0
diff changeset
144 static inline void
kono
parents: 0
diff changeset
145 gomp_clear_parent (struct priority_queue *q)
kono
parents: 0
diff changeset
146 {
kono
parents: 0
diff changeset
147 if (priority_queue_multi_p (q))
kono
parents: 0
diff changeset
148 {
kono
parents: 0
diff changeset
149 gomp_clear_parent_in_tree (&q->t, q->t.root);
kono
parents: 0
diff changeset
150 /* All the nodes have been cleared in gomp_clear_parent_in_tree.
kono
parents: 0
diff changeset
151 No need to remove anything. We can just nuke everything. */
kono
parents: 0
diff changeset
152 q->t.root = NULL;
kono
parents: 0
diff changeset
153 }
kono
parents: 0
diff changeset
154 else
kono
parents: 0
diff changeset
155 gomp_clear_parent_in_list (&q->l);
kono
parents: 0
diff changeset
156 }
kono
parents: 0
diff changeset
157
kono
parents: 0
diff changeset
158 /* Helper function for GOMP_task and gomp_create_target_task.
kono
parents: 0
diff changeset
159
kono
parents: 0
diff changeset
160 For a TASK with in/out dependencies, fill in the various dependency
kono
parents: 0
diff changeset
161 queues. PARENT is the parent of said task. DEPEND is as in
kono
parents: 0
diff changeset
162 GOMP_task. */
kono
parents: 0
diff changeset
163
kono
parents: 0
diff changeset
164 static void
kono
parents: 0
diff changeset
165 gomp_task_handle_depend (struct gomp_task *task, struct gomp_task *parent,
kono
parents: 0
diff changeset
166 void **depend)
kono
parents: 0
diff changeset
167 {
kono
parents: 0
diff changeset
168 size_t ndepend = (uintptr_t) depend[0];
kono
parents: 0
diff changeset
169 size_t i;
kono
parents: 0
diff changeset
170 hash_entry_type ent;
kono
parents: 0
diff changeset
171
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
172 if (ndepend)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
173 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
174 /* depend[0] is total # */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
175 size_t nout = (uintptr_t) depend[1]; /* # of out: and inout: */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
176 /* ndepend - nout is # of in: */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
177 for (i = 0; i < ndepend; i++)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
178 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
179 task->depend[i].addr = depend[2 + i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
180 task->depend[i].is_in = i >= nout;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
181 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
182 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
183 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
184 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
185 ndepend = (uintptr_t) depend[1]; /* total # */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
186 size_t nout = (uintptr_t) depend[2]; /* # of out: and inout: */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
187 size_t nmutexinoutset = (uintptr_t) depend[3]; /* # of mutexinoutset: */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
188 /* For now we treat mutexinoutset like out, which is compliant, but
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
189 inefficient. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
190 size_t nin = (uintptr_t) depend[4]; /* # of in: */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
191 /* ndepend - nout - nmutexinoutset - nin is # of depobjs */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
192 size_t normal = nout + nmutexinoutset + nin;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
193 size_t n = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
194 for (i = normal; i < ndepend; i++)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
195 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
196 void **d = (void **) (uintptr_t) depend[5 + i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
197 switch ((uintptr_t) d[1])
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
198 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
199 case GOMP_DEPEND_OUT:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
200 case GOMP_DEPEND_INOUT:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
201 case GOMP_DEPEND_MUTEXINOUTSET:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
202 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
203 case GOMP_DEPEND_IN:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
204 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
205 default:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
206 gomp_fatal ("unknown omp_depend_t dependence type %d",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
207 (int) (uintptr_t) d[1]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
208 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
209 task->depend[n].addr = d[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
210 task->depend[n++].is_in = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
211 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
212 for (i = 0; i < normal; i++)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
213 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
214 task->depend[n].addr = depend[5 + i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
215 task->depend[n++].is_in = i >= nout + nmutexinoutset;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
216 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
217 for (i = normal; i < ndepend; i++)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
218 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
219 void **d = (void **) (uintptr_t) depend[5 + i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
220 if ((uintptr_t) d[1] != GOMP_DEPEND_IN)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
221 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
222 task->depend[n].addr = d[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
223 task->depend[n++].is_in = 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
224 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
225 }
111
kono
parents: 0
diff changeset
226 task->depend_count = ndepend;
kono
parents: 0
diff changeset
227 task->num_dependees = 0;
kono
parents: 0
diff changeset
228 if (parent->depend_hash == NULL)
kono
parents: 0
diff changeset
229 parent->depend_hash = htab_create (2 * ndepend > 12 ? 2 * ndepend : 12);
kono
parents: 0
diff changeset
230 for (i = 0; i < ndepend; i++)
kono
parents: 0
diff changeset
231 {
kono
parents: 0
diff changeset
232 task->depend[i].next = NULL;
kono
parents: 0
diff changeset
233 task->depend[i].prev = NULL;
kono
parents: 0
diff changeset
234 task->depend[i].task = task;
kono
parents: 0
diff changeset
235 task->depend[i].redundant = false;
kono
parents: 0
diff changeset
236 task->depend[i].redundant_out = false;
kono
parents: 0
diff changeset
237
kono
parents: 0
diff changeset
238 hash_entry_type *slot = htab_find_slot (&parent->depend_hash,
kono
parents: 0
diff changeset
239 &task->depend[i], INSERT);
kono
parents: 0
diff changeset
240 hash_entry_type out = NULL, last = NULL;
kono
parents: 0
diff changeset
241 if (*slot)
kono
parents: 0
diff changeset
242 {
kono
parents: 0
diff changeset
243 /* If multiple depends on the same task are the same, all but the
kono
parents: 0
diff changeset
244 first one are redundant. As inout/out come first, if any of them
kono
parents: 0
diff changeset
245 is inout/out, it will win, which is the right semantics. */
kono
parents: 0
diff changeset
246 if ((*slot)->task == task)
kono
parents: 0
diff changeset
247 {
kono
parents: 0
diff changeset
248 task->depend[i].redundant = true;
kono
parents: 0
diff changeset
249 continue;
kono
parents: 0
diff changeset
250 }
kono
parents: 0
diff changeset
251 for (ent = *slot; ent; ent = ent->next)
kono
parents: 0
diff changeset
252 {
kono
parents: 0
diff changeset
253 if (ent->redundant_out)
kono
parents: 0
diff changeset
254 break;
kono
parents: 0
diff changeset
255
kono
parents: 0
diff changeset
256 last = ent;
kono
parents: 0
diff changeset
257
kono
parents: 0
diff changeset
258 /* depend(in:...) doesn't depend on earlier depend(in:...). */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
259 if (task->depend[i].is_in && ent->is_in)
111
kono
parents: 0
diff changeset
260 continue;
kono
parents: 0
diff changeset
261
kono
parents: 0
diff changeset
262 if (!ent->is_in)
kono
parents: 0
diff changeset
263 out = ent;
kono
parents: 0
diff changeset
264
kono
parents: 0
diff changeset
265 struct gomp_task *tsk = ent->task;
kono
parents: 0
diff changeset
266 if (tsk->dependers == NULL)
kono
parents: 0
diff changeset
267 {
kono
parents: 0
diff changeset
268 tsk->dependers
kono
parents: 0
diff changeset
269 = gomp_malloc (sizeof (struct gomp_dependers_vec)
kono
parents: 0
diff changeset
270 + 6 * sizeof (struct gomp_task *));
kono
parents: 0
diff changeset
271 tsk->dependers->n_elem = 1;
kono
parents: 0
diff changeset
272 tsk->dependers->allocated = 6;
kono
parents: 0
diff changeset
273 tsk->dependers->elem[0] = task;
kono
parents: 0
diff changeset
274 task->num_dependees++;
kono
parents: 0
diff changeset
275 continue;
kono
parents: 0
diff changeset
276 }
kono
parents: 0
diff changeset
277 /* We already have some other dependency on tsk from earlier
kono
parents: 0
diff changeset
278 depend clause. */
kono
parents: 0
diff changeset
279 else if (tsk->dependers->n_elem
kono
parents: 0
diff changeset
280 && (tsk->dependers->elem[tsk->dependers->n_elem - 1]
kono
parents: 0
diff changeset
281 == task))
kono
parents: 0
diff changeset
282 continue;
kono
parents: 0
diff changeset
283 else if (tsk->dependers->n_elem == tsk->dependers->allocated)
kono
parents: 0
diff changeset
284 {
kono
parents: 0
diff changeset
285 tsk->dependers->allocated
kono
parents: 0
diff changeset
286 = tsk->dependers->allocated * 2 + 2;
kono
parents: 0
diff changeset
287 tsk->dependers
kono
parents: 0
diff changeset
288 = gomp_realloc (tsk->dependers,
kono
parents: 0
diff changeset
289 sizeof (struct gomp_dependers_vec)
kono
parents: 0
diff changeset
290 + (tsk->dependers->allocated
kono
parents: 0
diff changeset
291 * sizeof (struct gomp_task *)));
kono
parents: 0
diff changeset
292 }
kono
parents: 0
diff changeset
293 tsk->dependers->elem[tsk->dependers->n_elem++] = task;
kono
parents: 0
diff changeset
294 task->num_dependees++;
kono
parents: 0
diff changeset
295 }
kono
parents: 0
diff changeset
296 task->depend[i].next = *slot;
kono
parents: 0
diff changeset
297 (*slot)->prev = &task->depend[i];
kono
parents: 0
diff changeset
298 }
kono
parents: 0
diff changeset
299 *slot = &task->depend[i];
kono
parents: 0
diff changeset
300
kono
parents: 0
diff changeset
301 /* There is no need to store more than one depend({,in}out:) task per
kono
parents: 0
diff changeset
302 address in the hash table chain for the purpose of creation of
kono
parents: 0
diff changeset
303 deferred tasks, because each out depends on all earlier outs, thus it
kono
parents: 0
diff changeset
304 is enough to record just the last depend({,in}out:). For depend(in:),
kono
parents: 0
diff changeset
305 we need to keep all of the previous ones not terminated yet, because
kono
parents: 0
diff changeset
306 a later depend({,in}out:) might need to depend on all of them. So, if
kono
parents: 0
diff changeset
307 the new task's clause is depend({,in}out:), we know there is at most
kono
parents: 0
diff changeset
308 one other depend({,in}out:) clause in the list (out). For
kono
parents: 0
diff changeset
309 non-deferred tasks we want to see all outs, so they are moved to the
kono
parents: 0
diff changeset
310 end of the chain, after first redundant_out entry all following
kono
parents: 0
diff changeset
311 entries should be redundant_out. */
kono
parents: 0
diff changeset
312 if (!task->depend[i].is_in && out)
kono
parents: 0
diff changeset
313 {
kono
parents: 0
diff changeset
314 if (out != last)
kono
parents: 0
diff changeset
315 {
kono
parents: 0
diff changeset
316 out->next->prev = out->prev;
kono
parents: 0
diff changeset
317 out->prev->next = out->next;
kono
parents: 0
diff changeset
318 out->next = last->next;
kono
parents: 0
diff changeset
319 out->prev = last;
kono
parents: 0
diff changeset
320 last->next = out;
kono
parents: 0
diff changeset
321 if (out->next)
kono
parents: 0
diff changeset
322 out->next->prev = out;
kono
parents: 0
diff changeset
323 }
kono
parents: 0
diff changeset
324 out->redundant_out = true;
kono
parents: 0
diff changeset
325 }
kono
parents: 0
diff changeset
326 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 /* Called when encountering an explicit task directive. If IF_CLAUSE is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 false, then we must not delay in executing the task. If UNTIED is true,
111
kono
parents: 0
diff changeset
331 then the task may be executed by any member of the team.
kono
parents: 0
diff changeset
332
kono
parents: 0
diff changeset
333 DEPEND is an array containing:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
334 if depend[0] is non-zero, then:
111
kono
parents: 0
diff changeset
335 depend[0]: number of depend elements.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
336 depend[1]: number of depend elements of type "out/inout".
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
337 depend[2..N+1]: address of [1..N]th depend element.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
338 otherwise, when depend[0] is zero, then:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
339 depend[1]: number of depend elements.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
340 depend[2]: number of depend elements of type "out/inout".
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
341 depend[3]: number of depend elements of type "mutexinoutset".
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
342 depend[4]: number of depend elements of type "in".
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
343 depend[5..4+depend[2]+depend[3]+depend[4]]: address of depend elements
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
344 depend[5+depend[2]+depend[3]+depend[4]..4+depend[1]]: address of
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
345 omp_depend_t objects. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 GOMP_task (void (*fn) (void *), void *data, void (*cpyfn) (void *, void *),
111
kono
parents: 0
diff changeset
349 long arg_size, long arg_align, bool if_clause, unsigned flags,
kono
parents: 0
diff changeset
350 void **depend, int priority)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
354
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 #ifdef HAVE_BROKEN_POSIX_SEMAPHORES
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 /* If pthread_mutex_* is used for omp_*lock*, then each task must be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 tied to one thread all the time. This means UNTIED tasks must be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 tied and if CPYFN is non-NULL IF(0) must be forced, as CPYFN
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 might be running on different thread than FN. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 if (cpyfn)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 if_clause = false;
111
kono
parents: 0
diff changeset
362 flags &= ~GOMP_TASK_FLAG_UNTIED;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
111
kono
parents: 0
diff changeset
365 /* If parallel or taskgroup has been cancelled, don't start new tasks. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
366 if (__builtin_expect (gomp_cancel_var, 0) && team)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
367 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
368 if (gomp_team_barrier_cancelled (&team->barrier))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
369 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
370 if (thr->task->taskgroup)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
371 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
372 if (thr->task->taskgroup->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
373 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
374 if (thr->task->taskgroup->workshare
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
375 && thr->task->taskgroup->prev
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
376 && thr->task->taskgroup->prev->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
377 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
378 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
379 }
111
kono
parents: 0
diff changeset
380
kono
parents: 0
diff changeset
381 if ((flags & GOMP_TASK_FLAG_PRIORITY) == 0)
kono
parents: 0
diff changeset
382 priority = 0;
kono
parents: 0
diff changeset
383 else if (priority > gomp_max_task_priority_var)
kono
parents: 0
diff changeset
384 priority = gomp_max_task_priority_var;
kono
parents: 0
diff changeset
385
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 if (!if_clause || team == NULL
111
kono
parents: 0
diff changeset
387 || (thr->task && thr->task->final_task)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 || team->task_count > 64 * team->nthreads)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 struct gomp_task task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391
111
kono
parents: 0
diff changeset
392 /* If there are depend clauses and earlier deferred sibling tasks
kono
parents: 0
diff changeset
393 with depend clauses, check if there isn't a dependency. If there
kono
parents: 0
diff changeset
394 is, we need to wait for them. There is no need to handle
kono
parents: 0
diff changeset
395 depend clauses for non-deferred tasks other than this, because
kono
parents: 0
diff changeset
396 the parent task is suspended until the child task finishes and thus
kono
parents: 0
diff changeset
397 it can't start further child tasks. */
kono
parents: 0
diff changeset
398 if ((flags & GOMP_TASK_FLAG_DEPEND)
kono
parents: 0
diff changeset
399 && thr->task && thr->task->depend_hash)
kono
parents: 0
diff changeset
400 gomp_task_maybe_wait_for_dependencies (depend);
kono
parents: 0
diff changeset
401
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 gomp_init_task (&task, thr->task, gomp_icv (false));
111
kono
parents: 0
diff changeset
403 task.kind = GOMP_TASK_UNDEFERRED;
kono
parents: 0
diff changeset
404 task.final_task = (thr->task && thr->task->final_task)
kono
parents: 0
diff changeset
405 || (flags & GOMP_TASK_FLAG_FINAL);
kono
parents: 0
diff changeset
406 task.priority = priority;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 if (thr->task)
111
kono
parents: 0
diff changeset
408 {
kono
parents: 0
diff changeset
409 task.in_tied_task = thr->task->in_tied_task;
kono
parents: 0
diff changeset
410 task.taskgroup = thr->task->taskgroup;
kono
parents: 0
diff changeset
411 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 thr->task = &task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 if (__builtin_expect (cpyfn != NULL, 0))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 char buf[arg_size + arg_align - 1];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 char *arg = (char *) (((uintptr_t) buf + arg_align - 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 & ~(uintptr_t) (arg_align - 1));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 cpyfn (arg, data);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 fn (arg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 fn (data);
111
kono
parents: 0
diff changeset
423 /* Access to "children" is normally done inside a task_lock
kono
parents: 0
diff changeset
424 mutex region, but the only way this particular task.children
kono
parents: 0
diff changeset
425 can be set is if this thread's task work function (fn)
kono
parents: 0
diff changeset
426 creates children. So since the setter is *this* thread, we
kono
parents: 0
diff changeset
427 need no barriers here when testing for non-NULL. We can have
kono
parents: 0
diff changeset
428 task.children set by the current thread then changed by a
kono
parents: 0
diff changeset
429 child thread, but seeing a stale non-NULL value is not a
kono
parents: 0
diff changeset
430 problem. Once past the task_lock acquisition, this thread
kono
parents: 0
diff changeset
431 will see the real value of task.children. */
kono
parents: 0
diff changeset
432 if (!priority_queue_empty_p (&task.children_queue, MEMMODEL_RELAXED))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 gomp_mutex_lock (&team->task_lock);
111
kono
parents: 0
diff changeset
435 gomp_clear_parent (&task.children_queue);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 gomp_mutex_unlock (&team->task_lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 gomp_end_task ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 struct gomp_task *task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 struct gomp_task *parent = thr->task;
111
kono
parents: 0
diff changeset
444 struct gomp_taskgroup *taskgroup = parent->taskgroup;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 char *arg;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 bool do_wake;
111
kono
parents: 0
diff changeset
447 size_t depend_size = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448
111
kono
parents: 0
diff changeset
449 if (flags & GOMP_TASK_FLAG_DEPEND)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
450 depend_size = ((uintptr_t) (depend[0] ? depend[0] : depend[1])
111
kono
parents: 0
diff changeset
451 * sizeof (struct gomp_task_depend_entry));
kono
parents: 0
diff changeset
452 task = gomp_malloc (sizeof (*task) + depend_size
kono
parents: 0
diff changeset
453 + arg_size + arg_align - 1);
kono
parents: 0
diff changeset
454 arg = (char *) (((uintptr_t) (task + 1) + depend_size + arg_align - 1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 & ~(uintptr_t) (arg_align - 1));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 gomp_init_task (task, parent, gomp_icv (false));
111
kono
parents: 0
diff changeset
457 task->priority = priority;
kono
parents: 0
diff changeset
458 task->kind = GOMP_TASK_UNDEFERRED;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 task->in_tied_task = parent->in_tied_task;
111
kono
parents: 0
diff changeset
460 task->taskgroup = taskgroup;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 thr->task = task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 if (cpyfn)
111
kono
parents: 0
diff changeset
463 {
kono
parents: 0
diff changeset
464 cpyfn (arg, data);
kono
parents: 0
diff changeset
465 task->copy_ctors_done = true;
kono
parents: 0
diff changeset
466 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 memcpy (arg, data, arg_size);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 thr->task = parent;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 task->kind = GOMP_TASK_WAITING;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 task->fn = fn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 task->fn_data = arg;
111
kono
parents: 0
diff changeset
473 task->final_task = (flags & GOMP_TASK_FLAG_FINAL) >> 1;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 gomp_mutex_lock (&team->task_lock);
111
kono
parents: 0
diff changeset
475 /* If parallel or taskgroup has been cancelled, don't start new
kono
parents: 0
diff changeset
476 tasks. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
477 if (__builtin_expect (gomp_cancel_var, 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
478 && !task->copy_ctors_done)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
480 if (gomp_team_barrier_cancelled (&team->barrier))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
481 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
482 do_cancel:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
483 gomp_mutex_unlock (&team->task_lock);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
484 gomp_finish_task (task);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
485 free (task);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
486 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
487 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
488 if (taskgroup)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
489 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
490 if (taskgroup->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
491 goto do_cancel;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
492 if (taskgroup->workshare
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
493 && taskgroup->prev
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
494 && taskgroup->prev->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
495 goto do_cancel;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
496 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 }
111
kono
parents: 0
diff changeset
498 if (taskgroup)
kono
parents: 0
diff changeset
499 taskgroup->num_children++;
kono
parents: 0
diff changeset
500 if (depend_size)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 {
111
kono
parents: 0
diff changeset
502 gomp_task_handle_depend (task, parent, depend);
kono
parents: 0
diff changeset
503 if (task->num_dependees)
kono
parents: 0
diff changeset
504 {
kono
parents: 0
diff changeset
505 /* Tasks that depend on other tasks are not put into the
kono
parents: 0
diff changeset
506 various waiting queues, so we are done for now. Said
kono
parents: 0
diff changeset
507 tasks are instead put into the queues via
kono
parents: 0
diff changeset
508 gomp_task_run_post_handle_dependers() after their
kono
parents: 0
diff changeset
509 dependencies have been satisfied. After which, they
kono
parents: 0
diff changeset
510 can be picked up by the various scheduling
kono
parents: 0
diff changeset
511 points. */
kono
parents: 0
diff changeset
512 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
513 return;
kono
parents: 0
diff changeset
514 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 }
111
kono
parents: 0
diff changeset
516
kono
parents: 0
diff changeset
517 priority_queue_insert (PQ_CHILDREN, &parent->children_queue,
kono
parents: 0
diff changeset
518 task, priority,
kono
parents: 0
diff changeset
519 PRIORITY_INSERT_BEGIN,
kono
parents: 0
diff changeset
520 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
521 task->parent_depends_on);
kono
parents: 0
diff changeset
522 if (taskgroup)
kono
parents: 0
diff changeset
523 priority_queue_insert (PQ_TASKGROUP, &taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
524 task, priority,
kono
parents: 0
diff changeset
525 PRIORITY_INSERT_BEGIN,
kono
parents: 0
diff changeset
526 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
527 task->parent_depends_on);
kono
parents: 0
diff changeset
528
kono
parents: 0
diff changeset
529 priority_queue_insert (PQ_TEAM, &team->task_queue,
kono
parents: 0
diff changeset
530 task, priority,
kono
parents: 0
diff changeset
531 PRIORITY_INSERT_END,
kono
parents: 0
diff changeset
532 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
533 task->parent_depends_on);
kono
parents: 0
diff changeset
534
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 ++team->task_count;
111
kono
parents: 0
diff changeset
536 ++team->task_queued_count;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 gomp_team_barrier_set_task_pending (&team->barrier);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 do_wake = team->task_running_count + !parent->in_tied_task
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 < team->nthreads;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 gomp_mutex_unlock (&team->task_lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 if (do_wake)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 gomp_team_barrier_wake (&team->barrier, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545
111
kono
parents: 0
diff changeset
546 ialias (GOMP_taskgroup_start)
kono
parents: 0
diff changeset
547 ialias (GOMP_taskgroup_end)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
548 ialias (GOMP_taskgroup_reduction_register)
111
kono
parents: 0
diff changeset
549
kono
parents: 0
diff changeset
550 #define TYPE long
kono
parents: 0
diff changeset
551 #define UTYPE unsigned long
kono
parents: 0
diff changeset
552 #define TYPE_is_long 1
kono
parents: 0
diff changeset
553 #include "taskloop.c"
kono
parents: 0
diff changeset
554 #undef TYPE
kono
parents: 0
diff changeset
555 #undef UTYPE
kono
parents: 0
diff changeset
556 #undef TYPE_is_long
kono
parents: 0
diff changeset
557
kono
parents: 0
diff changeset
558 #define TYPE unsigned long long
kono
parents: 0
diff changeset
559 #define UTYPE TYPE
kono
parents: 0
diff changeset
560 #define GOMP_taskloop GOMP_taskloop_ull
kono
parents: 0
diff changeset
561 #include "taskloop.c"
kono
parents: 0
diff changeset
562 #undef TYPE
kono
parents: 0
diff changeset
563 #undef UTYPE
kono
parents: 0
diff changeset
564 #undef GOMP_taskloop
kono
parents: 0
diff changeset
565
kono
parents: 0
diff changeset
566 static void inline
kono
parents: 0
diff changeset
567 priority_queue_move_task_first (enum priority_queue_type type,
kono
parents: 0
diff changeset
568 struct priority_queue *head,
kono
parents: 0
diff changeset
569 struct gomp_task *task)
kono
parents: 0
diff changeset
570 {
kono
parents: 0
diff changeset
571 #if _LIBGOMP_CHECKING_
kono
parents: 0
diff changeset
572 if (!priority_queue_task_in_queue_p (type, head, task))
kono
parents: 0
diff changeset
573 gomp_fatal ("Attempt to move first missing task %p", task);
kono
parents: 0
diff changeset
574 #endif
kono
parents: 0
diff changeset
575 struct priority_list *list;
kono
parents: 0
diff changeset
576 if (priority_queue_multi_p (head))
kono
parents: 0
diff changeset
577 {
kono
parents: 0
diff changeset
578 list = priority_queue_lookup_priority (head, task->priority);
kono
parents: 0
diff changeset
579 #if _LIBGOMP_CHECKING_
kono
parents: 0
diff changeset
580 if (!list)
kono
parents: 0
diff changeset
581 gomp_fatal ("Unable to find priority %d", task->priority);
kono
parents: 0
diff changeset
582 #endif
kono
parents: 0
diff changeset
583 }
kono
parents: 0
diff changeset
584 else
kono
parents: 0
diff changeset
585 list = &head->l;
kono
parents: 0
diff changeset
586 priority_list_remove (list, task_to_priority_node (type, task), 0);
kono
parents: 0
diff changeset
587 priority_list_insert (type, list, task, task->priority,
kono
parents: 0
diff changeset
588 PRIORITY_INSERT_BEGIN, type == PQ_CHILDREN,
kono
parents: 0
diff changeset
589 task->parent_depends_on);
kono
parents: 0
diff changeset
590 }
kono
parents: 0
diff changeset
591
kono
parents: 0
diff changeset
592 /* Actual body of GOMP_PLUGIN_target_task_completion that is executed
kono
parents: 0
diff changeset
593 with team->task_lock held, or is executed in the thread that called
kono
parents: 0
diff changeset
594 gomp_target_task_fn if GOMP_PLUGIN_target_task_completion has been
kono
parents: 0
diff changeset
595 run before it acquires team->task_lock. */
kono
parents: 0
diff changeset
596
kono
parents: 0
diff changeset
597 static void
kono
parents: 0
diff changeset
598 gomp_target_task_completion (struct gomp_team *team, struct gomp_task *task)
kono
parents: 0
diff changeset
599 {
kono
parents: 0
diff changeset
600 struct gomp_task *parent = task->parent;
kono
parents: 0
diff changeset
601 if (parent)
kono
parents: 0
diff changeset
602 priority_queue_move_task_first (PQ_CHILDREN, &parent->children_queue,
kono
parents: 0
diff changeset
603 task);
kono
parents: 0
diff changeset
604
kono
parents: 0
diff changeset
605 struct gomp_taskgroup *taskgroup = task->taskgroup;
kono
parents: 0
diff changeset
606 if (taskgroup)
kono
parents: 0
diff changeset
607 priority_queue_move_task_first (PQ_TASKGROUP, &taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
608 task);
kono
parents: 0
diff changeset
609
kono
parents: 0
diff changeset
610 priority_queue_insert (PQ_TEAM, &team->task_queue, task, task->priority,
kono
parents: 0
diff changeset
611 PRIORITY_INSERT_BEGIN, false,
kono
parents: 0
diff changeset
612 task->parent_depends_on);
kono
parents: 0
diff changeset
613 task->kind = GOMP_TASK_WAITING;
kono
parents: 0
diff changeset
614 if (parent && parent->taskwait)
kono
parents: 0
diff changeset
615 {
kono
parents: 0
diff changeset
616 if (parent->taskwait->in_taskwait)
kono
parents: 0
diff changeset
617 {
kono
parents: 0
diff changeset
618 /* One more task has had its dependencies met.
kono
parents: 0
diff changeset
619 Inform any waiters. */
kono
parents: 0
diff changeset
620 parent->taskwait->in_taskwait = false;
kono
parents: 0
diff changeset
621 gomp_sem_post (&parent->taskwait->taskwait_sem);
kono
parents: 0
diff changeset
622 }
kono
parents: 0
diff changeset
623 else if (parent->taskwait->in_depend_wait)
kono
parents: 0
diff changeset
624 {
kono
parents: 0
diff changeset
625 /* One more task has had its dependencies met.
kono
parents: 0
diff changeset
626 Inform any waiters. */
kono
parents: 0
diff changeset
627 parent->taskwait->in_depend_wait = false;
kono
parents: 0
diff changeset
628 gomp_sem_post (&parent->taskwait->taskwait_sem);
kono
parents: 0
diff changeset
629 }
kono
parents: 0
diff changeset
630 }
kono
parents: 0
diff changeset
631 if (taskgroup && taskgroup->in_taskgroup_wait)
kono
parents: 0
diff changeset
632 {
kono
parents: 0
diff changeset
633 /* One more task has had its dependencies met.
kono
parents: 0
diff changeset
634 Inform any waiters. */
kono
parents: 0
diff changeset
635 taskgroup->in_taskgroup_wait = false;
kono
parents: 0
diff changeset
636 gomp_sem_post (&taskgroup->taskgroup_sem);
kono
parents: 0
diff changeset
637 }
kono
parents: 0
diff changeset
638
kono
parents: 0
diff changeset
639 ++team->task_queued_count;
kono
parents: 0
diff changeset
640 gomp_team_barrier_set_task_pending (&team->barrier);
kono
parents: 0
diff changeset
641 /* I'm afraid this can't be done after releasing team->task_lock,
kono
parents: 0
diff changeset
642 as gomp_target_task_completion is run from unrelated thread and
kono
parents: 0
diff changeset
643 therefore in between gomp_mutex_unlock and gomp_team_barrier_wake
kono
parents: 0
diff changeset
644 the team could be gone already. */
kono
parents: 0
diff changeset
645 if (team->nthreads > team->task_running_count)
kono
parents: 0
diff changeset
646 gomp_team_barrier_wake (&team->barrier, 1);
kono
parents: 0
diff changeset
647 }
kono
parents: 0
diff changeset
648
kono
parents: 0
diff changeset
649 /* Signal that a target task TTASK has completed the asynchronously
kono
parents: 0
diff changeset
650 running phase and should be requeued as a task to handle the
kono
parents: 0
diff changeset
651 variable unmapping. */
kono
parents: 0
diff changeset
652
kono
parents: 0
diff changeset
653 void
kono
parents: 0
diff changeset
654 GOMP_PLUGIN_target_task_completion (void *data)
kono
parents: 0
diff changeset
655 {
kono
parents: 0
diff changeset
656 struct gomp_target_task *ttask = (struct gomp_target_task *) data;
kono
parents: 0
diff changeset
657 struct gomp_task *task = ttask->task;
kono
parents: 0
diff changeset
658 struct gomp_team *team = ttask->team;
kono
parents: 0
diff changeset
659
kono
parents: 0
diff changeset
660 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
661 if (ttask->state == GOMP_TARGET_TASK_READY_TO_RUN)
kono
parents: 0
diff changeset
662 {
kono
parents: 0
diff changeset
663 ttask->state = GOMP_TARGET_TASK_FINISHED;
kono
parents: 0
diff changeset
664 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
665 return;
kono
parents: 0
diff changeset
666 }
kono
parents: 0
diff changeset
667 ttask->state = GOMP_TARGET_TASK_FINISHED;
kono
parents: 0
diff changeset
668 gomp_target_task_completion (team, task);
kono
parents: 0
diff changeset
669 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
670 }
kono
parents: 0
diff changeset
671
kono
parents: 0
diff changeset
672 static void gomp_task_run_post_handle_depend_hash (struct gomp_task *);
kono
parents: 0
diff changeset
673
kono
parents: 0
diff changeset
674 /* Called for nowait target tasks. */
kono
parents: 0
diff changeset
675
kono
parents: 0
diff changeset
676 bool
kono
parents: 0
diff changeset
677 gomp_create_target_task (struct gomp_device_descr *devicep,
kono
parents: 0
diff changeset
678 void (*fn) (void *), size_t mapnum, void **hostaddrs,
kono
parents: 0
diff changeset
679 size_t *sizes, unsigned short *kinds,
kono
parents: 0
diff changeset
680 unsigned int flags, void **depend, void **args,
kono
parents: 0
diff changeset
681 enum gomp_target_task_state state)
kono
parents: 0
diff changeset
682 {
kono
parents: 0
diff changeset
683 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
684 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
685
kono
parents: 0
diff changeset
686 /* If parallel or taskgroup has been cancelled, don't start new tasks. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
687 if (__builtin_expect (gomp_cancel_var, 0) && team)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
688 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
689 if (gomp_team_barrier_cancelled (&team->barrier))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
690 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
691 if (thr->task->taskgroup)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
692 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
693 if (thr->task->taskgroup->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
694 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
695 if (thr->task->taskgroup->workshare
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
696 && thr->task->taskgroup->prev
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
697 && thr->task->taskgroup->prev->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
698 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
699 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
700 }
111
kono
parents: 0
diff changeset
701
kono
parents: 0
diff changeset
702 struct gomp_target_task *ttask;
kono
parents: 0
diff changeset
703 struct gomp_task *task;
kono
parents: 0
diff changeset
704 struct gomp_task *parent = thr->task;
kono
parents: 0
diff changeset
705 struct gomp_taskgroup *taskgroup = parent->taskgroup;
kono
parents: 0
diff changeset
706 bool do_wake;
kono
parents: 0
diff changeset
707 size_t depend_size = 0;
kono
parents: 0
diff changeset
708 uintptr_t depend_cnt = 0;
kono
parents: 0
diff changeset
709 size_t tgt_align = 0, tgt_size = 0;
kono
parents: 0
diff changeset
710
kono
parents: 0
diff changeset
711 if (depend != NULL)
kono
parents: 0
diff changeset
712 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
713 depend_cnt = (uintptr_t) (depend[0] ? depend[0] : depend[1]);
111
kono
parents: 0
diff changeset
714 depend_size = depend_cnt * sizeof (struct gomp_task_depend_entry);
kono
parents: 0
diff changeset
715 }
kono
parents: 0
diff changeset
716 if (fn)
kono
parents: 0
diff changeset
717 {
kono
parents: 0
diff changeset
718 /* GOMP_MAP_FIRSTPRIVATE need to be copied first, as they are
kono
parents: 0
diff changeset
719 firstprivate on the target task. */
kono
parents: 0
diff changeset
720 size_t i;
kono
parents: 0
diff changeset
721 for (i = 0; i < mapnum; i++)
kono
parents: 0
diff changeset
722 if ((kinds[i] & 0xff) == GOMP_MAP_FIRSTPRIVATE)
kono
parents: 0
diff changeset
723 {
kono
parents: 0
diff changeset
724 size_t align = (size_t) 1 << (kinds[i] >> 8);
kono
parents: 0
diff changeset
725 if (tgt_align < align)
kono
parents: 0
diff changeset
726 tgt_align = align;
kono
parents: 0
diff changeset
727 tgt_size = (tgt_size + align - 1) & ~(align - 1);
kono
parents: 0
diff changeset
728 tgt_size += sizes[i];
kono
parents: 0
diff changeset
729 }
kono
parents: 0
diff changeset
730 if (tgt_align)
kono
parents: 0
diff changeset
731 tgt_size += tgt_align - 1;
kono
parents: 0
diff changeset
732 else
kono
parents: 0
diff changeset
733 tgt_size = 0;
kono
parents: 0
diff changeset
734 }
kono
parents: 0
diff changeset
735
kono
parents: 0
diff changeset
736 task = gomp_malloc (sizeof (*task) + depend_size
kono
parents: 0
diff changeset
737 + sizeof (*ttask)
kono
parents: 0
diff changeset
738 + mapnum * (sizeof (void *) + sizeof (size_t)
kono
parents: 0
diff changeset
739 + sizeof (unsigned short))
kono
parents: 0
diff changeset
740 + tgt_size);
kono
parents: 0
diff changeset
741 gomp_init_task (task, parent, gomp_icv (false));
kono
parents: 0
diff changeset
742 task->priority = 0;
kono
parents: 0
diff changeset
743 task->kind = GOMP_TASK_WAITING;
kono
parents: 0
diff changeset
744 task->in_tied_task = parent->in_tied_task;
kono
parents: 0
diff changeset
745 task->taskgroup = taskgroup;
kono
parents: 0
diff changeset
746 ttask = (struct gomp_target_task *) &task->depend[depend_cnt];
kono
parents: 0
diff changeset
747 ttask->devicep = devicep;
kono
parents: 0
diff changeset
748 ttask->fn = fn;
kono
parents: 0
diff changeset
749 ttask->mapnum = mapnum;
kono
parents: 0
diff changeset
750 ttask->args = args;
kono
parents: 0
diff changeset
751 memcpy (ttask->hostaddrs, hostaddrs, mapnum * sizeof (void *));
kono
parents: 0
diff changeset
752 ttask->sizes = (size_t *) &ttask->hostaddrs[mapnum];
kono
parents: 0
diff changeset
753 memcpy (ttask->sizes, sizes, mapnum * sizeof (size_t));
kono
parents: 0
diff changeset
754 ttask->kinds = (unsigned short *) &ttask->sizes[mapnum];
kono
parents: 0
diff changeset
755 memcpy (ttask->kinds, kinds, mapnum * sizeof (unsigned short));
kono
parents: 0
diff changeset
756 if (tgt_align)
kono
parents: 0
diff changeset
757 {
kono
parents: 0
diff changeset
758 char *tgt = (char *) &ttask->kinds[mapnum];
kono
parents: 0
diff changeset
759 size_t i;
kono
parents: 0
diff changeset
760 uintptr_t al = (uintptr_t) tgt & (tgt_align - 1);
kono
parents: 0
diff changeset
761 if (al)
kono
parents: 0
diff changeset
762 tgt += tgt_align - al;
kono
parents: 0
diff changeset
763 tgt_size = 0;
kono
parents: 0
diff changeset
764 for (i = 0; i < mapnum; i++)
kono
parents: 0
diff changeset
765 if ((kinds[i] & 0xff) == GOMP_MAP_FIRSTPRIVATE)
kono
parents: 0
diff changeset
766 {
kono
parents: 0
diff changeset
767 size_t align = (size_t) 1 << (kinds[i] >> 8);
kono
parents: 0
diff changeset
768 tgt_size = (tgt_size + align - 1) & ~(align - 1);
kono
parents: 0
diff changeset
769 memcpy (tgt + tgt_size, hostaddrs[i], sizes[i]);
kono
parents: 0
diff changeset
770 ttask->hostaddrs[i] = tgt + tgt_size;
kono
parents: 0
diff changeset
771 tgt_size = tgt_size + sizes[i];
kono
parents: 0
diff changeset
772 }
kono
parents: 0
diff changeset
773 }
kono
parents: 0
diff changeset
774 ttask->flags = flags;
kono
parents: 0
diff changeset
775 ttask->state = state;
kono
parents: 0
diff changeset
776 ttask->task = task;
kono
parents: 0
diff changeset
777 ttask->team = team;
kono
parents: 0
diff changeset
778 task->fn = NULL;
kono
parents: 0
diff changeset
779 task->fn_data = ttask;
kono
parents: 0
diff changeset
780 task->final_task = 0;
kono
parents: 0
diff changeset
781 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
782 /* If parallel or taskgroup has been cancelled, don't start new tasks. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
783 if (__builtin_expect (gomp_cancel_var, 0))
111
kono
parents: 0
diff changeset
784 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
785 if (gomp_team_barrier_cancelled (&team->barrier))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
786 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
787 do_cancel:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
788 gomp_mutex_unlock (&team->task_lock);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
789 gomp_finish_task (task);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
790 free (task);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
791 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
792 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
793 if (taskgroup)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
794 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
795 if (taskgroup->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
796 goto do_cancel;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
797 if (taskgroup->workshare
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
798 && taskgroup->prev
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
799 && taskgroup->prev->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
800 goto do_cancel;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
801 }
111
kono
parents: 0
diff changeset
802 }
kono
parents: 0
diff changeset
803 if (depend_size)
kono
parents: 0
diff changeset
804 {
kono
parents: 0
diff changeset
805 gomp_task_handle_depend (task, parent, depend);
kono
parents: 0
diff changeset
806 if (task->num_dependees)
kono
parents: 0
diff changeset
807 {
kono
parents: 0
diff changeset
808 if (taskgroup)
kono
parents: 0
diff changeset
809 taskgroup->num_children++;
kono
parents: 0
diff changeset
810 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
811 return true;
kono
parents: 0
diff changeset
812 }
kono
parents: 0
diff changeset
813 }
kono
parents: 0
diff changeset
814 if (state == GOMP_TARGET_TASK_DATA)
kono
parents: 0
diff changeset
815 {
kono
parents: 0
diff changeset
816 gomp_task_run_post_handle_depend_hash (task);
kono
parents: 0
diff changeset
817 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
818 gomp_finish_task (task);
kono
parents: 0
diff changeset
819 free (task);
kono
parents: 0
diff changeset
820 return false;
kono
parents: 0
diff changeset
821 }
kono
parents: 0
diff changeset
822 if (taskgroup)
kono
parents: 0
diff changeset
823 taskgroup->num_children++;
kono
parents: 0
diff changeset
824 /* For async offloading, if we don't need to wait for dependencies,
kono
parents: 0
diff changeset
825 run the gomp_target_task_fn right away, essentially schedule the
kono
parents: 0
diff changeset
826 mapping part of the task in the current thread. */
kono
parents: 0
diff changeset
827 if (devicep != NULL
kono
parents: 0
diff changeset
828 && (devicep->capabilities & GOMP_OFFLOAD_CAP_OPENMP_400))
kono
parents: 0
diff changeset
829 {
kono
parents: 0
diff changeset
830 priority_queue_insert (PQ_CHILDREN, &parent->children_queue, task, 0,
kono
parents: 0
diff changeset
831 PRIORITY_INSERT_END,
kono
parents: 0
diff changeset
832 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
833 task->parent_depends_on);
kono
parents: 0
diff changeset
834 if (taskgroup)
kono
parents: 0
diff changeset
835 priority_queue_insert (PQ_TASKGROUP, &taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
836 task, 0, PRIORITY_INSERT_END,
kono
parents: 0
diff changeset
837 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
838 task->parent_depends_on);
kono
parents: 0
diff changeset
839 task->pnode[PQ_TEAM].next = NULL;
kono
parents: 0
diff changeset
840 task->pnode[PQ_TEAM].prev = NULL;
kono
parents: 0
diff changeset
841 task->kind = GOMP_TASK_TIED;
kono
parents: 0
diff changeset
842 ++team->task_count;
kono
parents: 0
diff changeset
843 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
844
kono
parents: 0
diff changeset
845 thr->task = task;
kono
parents: 0
diff changeset
846 gomp_target_task_fn (task->fn_data);
kono
parents: 0
diff changeset
847 thr->task = parent;
kono
parents: 0
diff changeset
848
kono
parents: 0
diff changeset
849 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
850 task->kind = GOMP_TASK_ASYNC_RUNNING;
kono
parents: 0
diff changeset
851 /* If GOMP_PLUGIN_target_task_completion has run already
kono
parents: 0
diff changeset
852 in between gomp_target_task_fn and the mutex lock,
kono
parents: 0
diff changeset
853 perform the requeuing here. */
kono
parents: 0
diff changeset
854 if (ttask->state == GOMP_TARGET_TASK_FINISHED)
kono
parents: 0
diff changeset
855 gomp_target_task_completion (team, task);
kono
parents: 0
diff changeset
856 else
kono
parents: 0
diff changeset
857 ttask->state = GOMP_TARGET_TASK_RUNNING;
kono
parents: 0
diff changeset
858 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
859 return true;
kono
parents: 0
diff changeset
860 }
kono
parents: 0
diff changeset
861 priority_queue_insert (PQ_CHILDREN, &parent->children_queue, task, 0,
kono
parents: 0
diff changeset
862 PRIORITY_INSERT_BEGIN,
kono
parents: 0
diff changeset
863 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
864 task->parent_depends_on);
kono
parents: 0
diff changeset
865 if (taskgroup)
kono
parents: 0
diff changeset
866 priority_queue_insert (PQ_TASKGROUP, &taskgroup->taskgroup_queue, task, 0,
kono
parents: 0
diff changeset
867 PRIORITY_INSERT_BEGIN,
kono
parents: 0
diff changeset
868 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
869 task->parent_depends_on);
kono
parents: 0
diff changeset
870 priority_queue_insert (PQ_TEAM, &team->task_queue, task, 0,
kono
parents: 0
diff changeset
871 PRIORITY_INSERT_END,
kono
parents: 0
diff changeset
872 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
873 task->parent_depends_on);
kono
parents: 0
diff changeset
874 ++team->task_count;
kono
parents: 0
diff changeset
875 ++team->task_queued_count;
kono
parents: 0
diff changeset
876 gomp_team_barrier_set_task_pending (&team->barrier);
kono
parents: 0
diff changeset
877 do_wake = team->task_running_count + !parent->in_tied_task
kono
parents: 0
diff changeset
878 < team->nthreads;
kono
parents: 0
diff changeset
879 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
880 if (do_wake)
kono
parents: 0
diff changeset
881 gomp_team_barrier_wake (&team->barrier, 1);
kono
parents: 0
diff changeset
882 return true;
kono
parents: 0
diff changeset
883 }
kono
parents: 0
diff changeset
884
kono
parents: 0
diff changeset
885 /* Given a parent_depends_on task in LIST, move it to the front of its
kono
parents: 0
diff changeset
886 priority so it is run as soon as possible.
kono
parents: 0
diff changeset
887
kono
parents: 0
diff changeset
888 Care is taken to update the list's LAST_PARENT_DEPENDS_ON field.
kono
parents: 0
diff changeset
889
kono
parents: 0
diff changeset
890 We rearrange the queue such that all parent_depends_on tasks are
kono
parents: 0
diff changeset
891 first, and last_parent_depends_on points to the last such task we
kono
parents: 0
diff changeset
892 rearranged. For example, given the following tasks in a queue
kono
parents: 0
diff changeset
893 where PD[123] are the parent_depends_on tasks:
kono
parents: 0
diff changeset
894
kono
parents: 0
diff changeset
895 task->children
kono
parents: 0
diff changeset
896 |
kono
parents: 0
diff changeset
897 V
kono
parents: 0
diff changeset
898 C1 -> C2 -> C3 -> PD1 -> PD2 -> PD3 -> C4
kono
parents: 0
diff changeset
899
kono
parents: 0
diff changeset
900 We rearrange such that:
kono
parents: 0
diff changeset
901
kono
parents: 0
diff changeset
902 task->children
kono
parents: 0
diff changeset
903 | +--- last_parent_depends_on
kono
parents: 0
diff changeset
904 | |
kono
parents: 0
diff changeset
905 V V
kono
parents: 0
diff changeset
906 PD1 -> PD2 -> PD3 -> C1 -> C2 -> C3 -> C4. */
kono
parents: 0
diff changeset
907
kono
parents: 0
diff changeset
908 static void inline
kono
parents: 0
diff changeset
909 priority_list_upgrade_task (struct priority_list *list,
kono
parents: 0
diff changeset
910 struct priority_node *node)
kono
parents: 0
diff changeset
911 {
kono
parents: 0
diff changeset
912 struct priority_node *last_parent_depends_on
kono
parents: 0
diff changeset
913 = list->last_parent_depends_on;
kono
parents: 0
diff changeset
914 if (last_parent_depends_on)
kono
parents: 0
diff changeset
915 {
kono
parents: 0
diff changeset
916 node->prev->next = node->next;
kono
parents: 0
diff changeset
917 node->next->prev = node->prev;
kono
parents: 0
diff changeset
918 node->prev = last_parent_depends_on;
kono
parents: 0
diff changeset
919 node->next = last_parent_depends_on->next;
kono
parents: 0
diff changeset
920 node->prev->next = node;
kono
parents: 0
diff changeset
921 node->next->prev = node;
kono
parents: 0
diff changeset
922 }
kono
parents: 0
diff changeset
923 else if (node != list->tasks)
kono
parents: 0
diff changeset
924 {
kono
parents: 0
diff changeset
925 node->prev->next = node->next;
kono
parents: 0
diff changeset
926 node->next->prev = node->prev;
kono
parents: 0
diff changeset
927 node->prev = list->tasks->prev;
kono
parents: 0
diff changeset
928 node->next = list->tasks;
kono
parents: 0
diff changeset
929 list->tasks = node;
kono
parents: 0
diff changeset
930 node->prev->next = node;
kono
parents: 0
diff changeset
931 node->next->prev = node;
kono
parents: 0
diff changeset
932 }
kono
parents: 0
diff changeset
933 list->last_parent_depends_on = node;
kono
parents: 0
diff changeset
934 }
kono
parents: 0
diff changeset
935
kono
parents: 0
diff changeset
936 /* Given a parent_depends_on TASK in its parent's children_queue, move
kono
parents: 0
diff changeset
937 it to the front of its priority so it is run as soon as possible.
kono
parents: 0
diff changeset
938
kono
parents: 0
diff changeset
939 PARENT is passed as an optimization.
kono
parents: 0
diff changeset
940
kono
parents: 0
diff changeset
941 (This function could be defined in priority_queue.c, but we want it
kono
parents: 0
diff changeset
942 inlined, and putting it in priority_queue.h is not an option, given
kono
parents: 0
diff changeset
943 that gomp_task has not been properly defined at that point). */
kono
parents: 0
diff changeset
944
kono
parents: 0
diff changeset
945 static void inline
kono
parents: 0
diff changeset
946 priority_queue_upgrade_task (struct gomp_task *task,
kono
parents: 0
diff changeset
947 struct gomp_task *parent)
kono
parents: 0
diff changeset
948 {
kono
parents: 0
diff changeset
949 struct priority_queue *head = &parent->children_queue;
kono
parents: 0
diff changeset
950 struct priority_node *node = &task->pnode[PQ_CHILDREN];
kono
parents: 0
diff changeset
951 #if _LIBGOMP_CHECKING_
kono
parents: 0
diff changeset
952 if (!task->parent_depends_on)
kono
parents: 0
diff changeset
953 gomp_fatal ("priority_queue_upgrade_task: task must be a "
kono
parents: 0
diff changeset
954 "parent_depends_on task");
kono
parents: 0
diff changeset
955 if (!priority_queue_task_in_queue_p (PQ_CHILDREN, head, task))
kono
parents: 0
diff changeset
956 gomp_fatal ("priority_queue_upgrade_task: cannot find task=%p", task);
kono
parents: 0
diff changeset
957 #endif
kono
parents: 0
diff changeset
958 if (priority_queue_multi_p (head))
kono
parents: 0
diff changeset
959 {
kono
parents: 0
diff changeset
960 struct priority_list *list
kono
parents: 0
diff changeset
961 = priority_queue_lookup_priority (head, task->priority);
kono
parents: 0
diff changeset
962 priority_list_upgrade_task (list, node);
kono
parents: 0
diff changeset
963 }
kono
parents: 0
diff changeset
964 else
kono
parents: 0
diff changeset
965 priority_list_upgrade_task (&head->l, node);
kono
parents: 0
diff changeset
966 }
kono
parents: 0
diff changeset
967
kono
parents: 0
diff changeset
968 /* Given a CHILD_TASK in LIST that is about to be executed, move it out of
kono
parents: 0
diff changeset
969 the way in LIST so that other tasks can be considered for
kono
parents: 0
diff changeset
970 execution. LIST contains tasks of type TYPE.
kono
parents: 0
diff changeset
971
kono
parents: 0
diff changeset
972 Care is taken to update the queue's LAST_PARENT_DEPENDS_ON field
kono
parents: 0
diff changeset
973 if applicable. */
kono
parents: 0
diff changeset
974
kono
parents: 0
diff changeset
975 static void inline
kono
parents: 0
diff changeset
976 priority_list_downgrade_task (enum priority_queue_type type,
kono
parents: 0
diff changeset
977 struct priority_list *list,
kono
parents: 0
diff changeset
978 struct gomp_task *child_task)
kono
parents: 0
diff changeset
979 {
kono
parents: 0
diff changeset
980 struct priority_node *node = task_to_priority_node (type, child_task);
kono
parents: 0
diff changeset
981 if (list->tasks == node)
kono
parents: 0
diff changeset
982 list->tasks = node->next;
kono
parents: 0
diff changeset
983 else if (node->next != list->tasks)
kono
parents: 0
diff changeset
984 {
kono
parents: 0
diff changeset
985 /* The task in NODE is about to become TIED and TIED tasks
kono
parents: 0
diff changeset
986 cannot come before WAITING tasks. If we're about to
kono
parents: 0
diff changeset
987 leave the queue in such an indeterminate state, rewire
kono
parents: 0
diff changeset
988 things appropriately. However, a TIED task at the end is
kono
parents: 0
diff changeset
989 perfectly fine. */
kono
parents: 0
diff changeset
990 struct gomp_task *next_task = priority_node_to_task (type, node->next);
kono
parents: 0
diff changeset
991 if (next_task->kind == GOMP_TASK_WAITING)
kono
parents: 0
diff changeset
992 {
kono
parents: 0
diff changeset
993 /* Remove from list. */
kono
parents: 0
diff changeset
994 node->prev->next = node->next;
kono
parents: 0
diff changeset
995 node->next->prev = node->prev;
kono
parents: 0
diff changeset
996 /* Rewire at the end. */
kono
parents: 0
diff changeset
997 node->next = list->tasks;
kono
parents: 0
diff changeset
998 node->prev = list->tasks->prev;
kono
parents: 0
diff changeset
999 list->tasks->prev->next = node;
kono
parents: 0
diff changeset
1000 list->tasks->prev = node;
kono
parents: 0
diff changeset
1001 }
kono
parents: 0
diff changeset
1002 }
kono
parents: 0
diff changeset
1003
kono
parents: 0
diff changeset
1004 /* If the current task is the last_parent_depends_on for its
kono
parents: 0
diff changeset
1005 priority, adjust last_parent_depends_on appropriately. */
kono
parents: 0
diff changeset
1006 if (__builtin_expect (child_task->parent_depends_on, 0)
kono
parents: 0
diff changeset
1007 && list->last_parent_depends_on == node)
kono
parents: 0
diff changeset
1008 {
kono
parents: 0
diff changeset
1009 struct gomp_task *prev_child = priority_node_to_task (type, node->prev);
kono
parents: 0
diff changeset
1010 if (node->prev != node
kono
parents: 0
diff changeset
1011 && prev_child->kind == GOMP_TASK_WAITING
kono
parents: 0
diff changeset
1012 && prev_child->parent_depends_on)
kono
parents: 0
diff changeset
1013 list->last_parent_depends_on = node->prev;
kono
parents: 0
diff changeset
1014 else
kono
parents: 0
diff changeset
1015 {
kono
parents: 0
diff changeset
1016 /* There are no more parent_depends_on entries waiting
kono
parents: 0
diff changeset
1017 to run, clear the list. */
kono
parents: 0
diff changeset
1018 list->last_parent_depends_on = NULL;
kono
parents: 0
diff changeset
1019 }
kono
parents: 0
diff changeset
1020 }
kono
parents: 0
diff changeset
1021 }
kono
parents: 0
diff changeset
1022
kono
parents: 0
diff changeset
1023 /* Given a TASK in HEAD that is about to be executed, move it out of
kono
parents: 0
diff changeset
1024 the way so that other tasks can be considered for execution. HEAD
kono
parents: 0
diff changeset
1025 contains tasks of type TYPE.
kono
parents: 0
diff changeset
1026
kono
parents: 0
diff changeset
1027 Care is taken to update the queue's LAST_PARENT_DEPENDS_ON field
kono
parents: 0
diff changeset
1028 if applicable.
kono
parents: 0
diff changeset
1029
kono
parents: 0
diff changeset
1030 (This function could be defined in priority_queue.c, but we want it
kono
parents: 0
diff changeset
1031 inlined, and putting it in priority_queue.h is not an option, given
kono
parents: 0
diff changeset
1032 that gomp_task has not been properly defined at that point). */
kono
parents: 0
diff changeset
1033
kono
parents: 0
diff changeset
1034 static void inline
kono
parents: 0
diff changeset
1035 priority_queue_downgrade_task (enum priority_queue_type type,
kono
parents: 0
diff changeset
1036 struct priority_queue *head,
kono
parents: 0
diff changeset
1037 struct gomp_task *task)
kono
parents: 0
diff changeset
1038 {
kono
parents: 0
diff changeset
1039 #if _LIBGOMP_CHECKING_
kono
parents: 0
diff changeset
1040 if (!priority_queue_task_in_queue_p (type, head, task))
kono
parents: 0
diff changeset
1041 gomp_fatal ("Attempt to downgrade missing task %p", task);
kono
parents: 0
diff changeset
1042 #endif
kono
parents: 0
diff changeset
1043 if (priority_queue_multi_p (head))
kono
parents: 0
diff changeset
1044 {
kono
parents: 0
diff changeset
1045 struct priority_list *list
kono
parents: 0
diff changeset
1046 = priority_queue_lookup_priority (head, task->priority);
kono
parents: 0
diff changeset
1047 priority_list_downgrade_task (type, list, task);
kono
parents: 0
diff changeset
1048 }
kono
parents: 0
diff changeset
1049 else
kono
parents: 0
diff changeset
1050 priority_list_downgrade_task (type, &head->l, task);
kono
parents: 0
diff changeset
1051 }
kono
parents: 0
diff changeset
1052
kono
parents: 0
diff changeset
1053 /* Setup CHILD_TASK to execute. This is done by setting the task to
kono
parents: 0
diff changeset
1054 TIED, and updating all relevant queues so that CHILD_TASK is no
kono
parents: 0
diff changeset
1055 longer chosen for scheduling. Also, remove CHILD_TASK from the
kono
parents: 0
diff changeset
1056 overall team task queue entirely.
kono
parents: 0
diff changeset
1057
kono
parents: 0
diff changeset
1058 Return TRUE if task or its containing taskgroup has been
kono
parents: 0
diff changeset
1059 cancelled. */
kono
parents: 0
diff changeset
1060
kono
parents: 0
diff changeset
1061 static inline bool
kono
parents: 0
diff changeset
1062 gomp_task_run_pre (struct gomp_task *child_task, struct gomp_task *parent,
kono
parents: 0
diff changeset
1063 struct gomp_team *team)
kono
parents: 0
diff changeset
1064 {
kono
parents: 0
diff changeset
1065 #if _LIBGOMP_CHECKING_
kono
parents: 0
diff changeset
1066 if (child_task->parent)
kono
parents: 0
diff changeset
1067 priority_queue_verify (PQ_CHILDREN,
kono
parents: 0
diff changeset
1068 &child_task->parent->children_queue, true);
kono
parents: 0
diff changeset
1069 if (child_task->taskgroup)
kono
parents: 0
diff changeset
1070 priority_queue_verify (PQ_TASKGROUP,
kono
parents: 0
diff changeset
1071 &child_task->taskgroup->taskgroup_queue, false);
kono
parents: 0
diff changeset
1072 priority_queue_verify (PQ_TEAM, &team->task_queue, false);
kono
parents: 0
diff changeset
1073 #endif
kono
parents: 0
diff changeset
1074
kono
parents: 0
diff changeset
1075 /* Task is about to go tied, move it out of the way. */
kono
parents: 0
diff changeset
1076 if (parent)
kono
parents: 0
diff changeset
1077 priority_queue_downgrade_task (PQ_CHILDREN, &parent->children_queue,
kono
parents: 0
diff changeset
1078 child_task);
kono
parents: 0
diff changeset
1079
kono
parents: 0
diff changeset
1080 /* Task is about to go tied, move it out of the way. */
kono
parents: 0
diff changeset
1081 struct gomp_taskgroup *taskgroup = child_task->taskgroup;
kono
parents: 0
diff changeset
1082 if (taskgroup)
kono
parents: 0
diff changeset
1083 priority_queue_downgrade_task (PQ_TASKGROUP, &taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
1084 child_task);
kono
parents: 0
diff changeset
1085
kono
parents: 0
diff changeset
1086 priority_queue_remove (PQ_TEAM, &team->task_queue, child_task,
kono
parents: 0
diff changeset
1087 MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
1088 child_task->pnode[PQ_TEAM].next = NULL;
kono
parents: 0
diff changeset
1089 child_task->pnode[PQ_TEAM].prev = NULL;
kono
parents: 0
diff changeset
1090 child_task->kind = GOMP_TASK_TIED;
kono
parents: 0
diff changeset
1091
kono
parents: 0
diff changeset
1092 if (--team->task_queued_count == 0)
kono
parents: 0
diff changeset
1093 gomp_team_barrier_clear_task_pending (&team->barrier);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1094 if (__builtin_expect (gomp_cancel_var, 0)
111
kono
parents: 0
diff changeset
1095 && !child_task->copy_ctors_done)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1096 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1097 if (gomp_team_barrier_cancelled (&team->barrier))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1098 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1099 if (taskgroup)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1100 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1101 if (taskgroup->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1102 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1103 if (taskgroup->workshare
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1104 && taskgroup->prev
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1105 && taskgroup->prev->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1106 return true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1107 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1108 }
111
kono
parents: 0
diff changeset
1109 return false;
kono
parents: 0
diff changeset
1110 }
kono
parents: 0
diff changeset
1111
kono
parents: 0
diff changeset
1112 static void
kono
parents: 0
diff changeset
1113 gomp_task_run_post_handle_depend_hash (struct gomp_task *child_task)
kono
parents: 0
diff changeset
1114 {
kono
parents: 0
diff changeset
1115 struct gomp_task *parent = child_task->parent;
kono
parents: 0
diff changeset
1116 size_t i;
kono
parents: 0
diff changeset
1117
kono
parents: 0
diff changeset
1118 for (i = 0; i < child_task->depend_count; i++)
kono
parents: 0
diff changeset
1119 if (!child_task->depend[i].redundant)
kono
parents: 0
diff changeset
1120 {
kono
parents: 0
diff changeset
1121 if (child_task->depend[i].next)
kono
parents: 0
diff changeset
1122 child_task->depend[i].next->prev = child_task->depend[i].prev;
kono
parents: 0
diff changeset
1123 if (child_task->depend[i].prev)
kono
parents: 0
diff changeset
1124 child_task->depend[i].prev->next = child_task->depend[i].next;
kono
parents: 0
diff changeset
1125 else
kono
parents: 0
diff changeset
1126 {
kono
parents: 0
diff changeset
1127 hash_entry_type *slot
kono
parents: 0
diff changeset
1128 = htab_find_slot (&parent->depend_hash, &child_task->depend[i],
kono
parents: 0
diff changeset
1129 NO_INSERT);
kono
parents: 0
diff changeset
1130 if (*slot != &child_task->depend[i])
kono
parents: 0
diff changeset
1131 abort ();
kono
parents: 0
diff changeset
1132 if (child_task->depend[i].next)
kono
parents: 0
diff changeset
1133 *slot = child_task->depend[i].next;
kono
parents: 0
diff changeset
1134 else
kono
parents: 0
diff changeset
1135 htab_clear_slot (parent->depend_hash, slot);
kono
parents: 0
diff changeset
1136 }
kono
parents: 0
diff changeset
1137 }
kono
parents: 0
diff changeset
1138 }
kono
parents: 0
diff changeset
1139
kono
parents: 0
diff changeset
1140 /* After a CHILD_TASK has been run, adjust the dependency queue for
kono
parents: 0
diff changeset
1141 each task that depends on CHILD_TASK, to record the fact that there
kono
parents: 0
diff changeset
1142 is one less dependency to worry about. If a task that depended on
kono
parents: 0
diff changeset
1143 CHILD_TASK now has no dependencies, place it in the various queues
kono
parents: 0
diff changeset
1144 so it gets scheduled to run.
kono
parents: 0
diff changeset
1145
kono
parents: 0
diff changeset
1146 TEAM is the team to which CHILD_TASK belongs to. */
kono
parents: 0
diff changeset
1147
kono
parents: 0
diff changeset
1148 static size_t
kono
parents: 0
diff changeset
1149 gomp_task_run_post_handle_dependers (struct gomp_task *child_task,
kono
parents: 0
diff changeset
1150 struct gomp_team *team)
kono
parents: 0
diff changeset
1151 {
kono
parents: 0
diff changeset
1152 struct gomp_task *parent = child_task->parent;
kono
parents: 0
diff changeset
1153 size_t i, count = child_task->dependers->n_elem, ret = 0;
kono
parents: 0
diff changeset
1154 for (i = 0; i < count; i++)
kono
parents: 0
diff changeset
1155 {
kono
parents: 0
diff changeset
1156 struct gomp_task *task = child_task->dependers->elem[i];
kono
parents: 0
diff changeset
1157
kono
parents: 0
diff changeset
1158 /* CHILD_TASK satisfies a dependency for TASK. Keep track of
kono
parents: 0
diff changeset
1159 TASK's remaining dependencies. Once TASK has no other
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1160 dependencies, put it into the various queues so it will get
111
kono
parents: 0
diff changeset
1161 scheduled for execution. */
kono
parents: 0
diff changeset
1162 if (--task->num_dependees != 0)
kono
parents: 0
diff changeset
1163 continue;
kono
parents: 0
diff changeset
1164
kono
parents: 0
diff changeset
1165 struct gomp_taskgroup *taskgroup = task->taskgroup;
kono
parents: 0
diff changeset
1166 if (parent)
kono
parents: 0
diff changeset
1167 {
kono
parents: 0
diff changeset
1168 priority_queue_insert (PQ_CHILDREN, &parent->children_queue,
kono
parents: 0
diff changeset
1169 task, task->priority,
kono
parents: 0
diff changeset
1170 PRIORITY_INSERT_BEGIN,
kono
parents: 0
diff changeset
1171 /*adjust_parent_depends_on=*/true,
kono
parents: 0
diff changeset
1172 task->parent_depends_on);
kono
parents: 0
diff changeset
1173 if (parent->taskwait)
kono
parents: 0
diff changeset
1174 {
kono
parents: 0
diff changeset
1175 if (parent->taskwait->in_taskwait)
kono
parents: 0
diff changeset
1176 {
kono
parents: 0
diff changeset
1177 /* One more task has had its dependencies met.
kono
parents: 0
diff changeset
1178 Inform any waiters. */
kono
parents: 0
diff changeset
1179 parent->taskwait->in_taskwait = false;
kono
parents: 0
diff changeset
1180 gomp_sem_post (&parent->taskwait->taskwait_sem);
kono
parents: 0
diff changeset
1181 }
kono
parents: 0
diff changeset
1182 else if (parent->taskwait->in_depend_wait)
kono
parents: 0
diff changeset
1183 {
kono
parents: 0
diff changeset
1184 /* One more task has had its dependencies met.
kono
parents: 0
diff changeset
1185 Inform any waiters. */
kono
parents: 0
diff changeset
1186 parent->taskwait->in_depend_wait = false;
kono
parents: 0
diff changeset
1187 gomp_sem_post (&parent->taskwait->taskwait_sem);
kono
parents: 0
diff changeset
1188 }
kono
parents: 0
diff changeset
1189 }
kono
parents: 0
diff changeset
1190 }
kono
parents: 0
diff changeset
1191 if (taskgroup)
kono
parents: 0
diff changeset
1192 {
kono
parents: 0
diff changeset
1193 priority_queue_insert (PQ_TASKGROUP, &taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
1194 task, task->priority,
kono
parents: 0
diff changeset
1195 PRIORITY_INSERT_BEGIN,
kono
parents: 0
diff changeset
1196 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
1197 task->parent_depends_on);
kono
parents: 0
diff changeset
1198 if (taskgroup->in_taskgroup_wait)
kono
parents: 0
diff changeset
1199 {
kono
parents: 0
diff changeset
1200 /* One more task has had its dependencies met.
kono
parents: 0
diff changeset
1201 Inform any waiters. */
kono
parents: 0
diff changeset
1202 taskgroup->in_taskgroup_wait = false;
kono
parents: 0
diff changeset
1203 gomp_sem_post (&taskgroup->taskgroup_sem);
kono
parents: 0
diff changeset
1204 }
kono
parents: 0
diff changeset
1205 }
kono
parents: 0
diff changeset
1206 priority_queue_insert (PQ_TEAM, &team->task_queue,
kono
parents: 0
diff changeset
1207 task, task->priority,
kono
parents: 0
diff changeset
1208 PRIORITY_INSERT_END,
kono
parents: 0
diff changeset
1209 /*adjust_parent_depends_on=*/false,
kono
parents: 0
diff changeset
1210 task->parent_depends_on);
kono
parents: 0
diff changeset
1211 ++team->task_count;
kono
parents: 0
diff changeset
1212 ++team->task_queued_count;
kono
parents: 0
diff changeset
1213 ++ret;
kono
parents: 0
diff changeset
1214 }
kono
parents: 0
diff changeset
1215 free (child_task->dependers);
kono
parents: 0
diff changeset
1216 child_task->dependers = NULL;
kono
parents: 0
diff changeset
1217 if (ret > 1)
kono
parents: 0
diff changeset
1218 gomp_team_barrier_set_task_pending (&team->barrier);
kono
parents: 0
diff changeset
1219 return ret;
kono
parents: 0
diff changeset
1220 }
kono
parents: 0
diff changeset
1221
kono
parents: 0
diff changeset
1222 static inline size_t
kono
parents: 0
diff changeset
1223 gomp_task_run_post_handle_depend (struct gomp_task *child_task,
kono
parents: 0
diff changeset
1224 struct gomp_team *team)
kono
parents: 0
diff changeset
1225 {
kono
parents: 0
diff changeset
1226 if (child_task->depend_count == 0)
kono
parents: 0
diff changeset
1227 return 0;
kono
parents: 0
diff changeset
1228
kono
parents: 0
diff changeset
1229 /* If parent is gone already, the hash table is freed and nothing
kono
parents: 0
diff changeset
1230 will use the hash table anymore, no need to remove anything from it. */
kono
parents: 0
diff changeset
1231 if (child_task->parent != NULL)
kono
parents: 0
diff changeset
1232 gomp_task_run_post_handle_depend_hash (child_task);
kono
parents: 0
diff changeset
1233
kono
parents: 0
diff changeset
1234 if (child_task->dependers == NULL)
kono
parents: 0
diff changeset
1235 return 0;
kono
parents: 0
diff changeset
1236
kono
parents: 0
diff changeset
1237 return gomp_task_run_post_handle_dependers (child_task, team);
kono
parents: 0
diff changeset
1238 }
kono
parents: 0
diff changeset
1239
kono
parents: 0
diff changeset
1240 /* Remove CHILD_TASK from its parent. */
kono
parents: 0
diff changeset
1241
kono
parents: 0
diff changeset
1242 static inline void
kono
parents: 0
diff changeset
1243 gomp_task_run_post_remove_parent (struct gomp_task *child_task)
kono
parents: 0
diff changeset
1244 {
kono
parents: 0
diff changeset
1245 struct gomp_task *parent = child_task->parent;
kono
parents: 0
diff changeset
1246 if (parent == NULL)
kono
parents: 0
diff changeset
1247 return;
kono
parents: 0
diff changeset
1248
kono
parents: 0
diff changeset
1249 /* If this was the last task the parent was depending on,
kono
parents: 0
diff changeset
1250 synchronize with gomp_task_maybe_wait_for_dependencies so it can
kono
parents: 0
diff changeset
1251 clean up and return. */
kono
parents: 0
diff changeset
1252 if (__builtin_expect (child_task->parent_depends_on, 0)
kono
parents: 0
diff changeset
1253 && --parent->taskwait->n_depend == 0
kono
parents: 0
diff changeset
1254 && parent->taskwait->in_depend_wait)
kono
parents: 0
diff changeset
1255 {
kono
parents: 0
diff changeset
1256 parent->taskwait->in_depend_wait = false;
kono
parents: 0
diff changeset
1257 gomp_sem_post (&parent->taskwait->taskwait_sem);
kono
parents: 0
diff changeset
1258 }
kono
parents: 0
diff changeset
1259
kono
parents: 0
diff changeset
1260 if (priority_queue_remove (PQ_CHILDREN, &parent->children_queue,
kono
parents: 0
diff changeset
1261 child_task, MEMMODEL_RELEASE)
kono
parents: 0
diff changeset
1262 && parent->taskwait && parent->taskwait->in_taskwait)
kono
parents: 0
diff changeset
1263 {
kono
parents: 0
diff changeset
1264 parent->taskwait->in_taskwait = false;
kono
parents: 0
diff changeset
1265 gomp_sem_post (&parent->taskwait->taskwait_sem);
kono
parents: 0
diff changeset
1266 }
kono
parents: 0
diff changeset
1267 child_task->pnode[PQ_CHILDREN].next = NULL;
kono
parents: 0
diff changeset
1268 child_task->pnode[PQ_CHILDREN].prev = NULL;
kono
parents: 0
diff changeset
1269 }
kono
parents: 0
diff changeset
1270
kono
parents: 0
diff changeset
1271 /* Remove CHILD_TASK from its taskgroup. */
kono
parents: 0
diff changeset
1272
kono
parents: 0
diff changeset
1273 static inline void
kono
parents: 0
diff changeset
1274 gomp_task_run_post_remove_taskgroup (struct gomp_task *child_task)
kono
parents: 0
diff changeset
1275 {
kono
parents: 0
diff changeset
1276 struct gomp_taskgroup *taskgroup = child_task->taskgroup;
kono
parents: 0
diff changeset
1277 if (taskgroup == NULL)
kono
parents: 0
diff changeset
1278 return;
kono
parents: 0
diff changeset
1279 bool empty = priority_queue_remove (PQ_TASKGROUP,
kono
parents: 0
diff changeset
1280 &taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
1281 child_task, MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
1282 child_task->pnode[PQ_TASKGROUP].next = NULL;
kono
parents: 0
diff changeset
1283 child_task->pnode[PQ_TASKGROUP].prev = NULL;
kono
parents: 0
diff changeset
1284 if (taskgroup->num_children > 1)
kono
parents: 0
diff changeset
1285 --taskgroup->num_children;
kono
parents: 0
diff changeset
1286 else
kono
parents: 0
diff changeset
1287 {
kono
parents: 0
diff changeset
1288 /* We access taskgroup->num_children in GOMP_taskgroup_end
kono
parents: 0
diff changeset
1289 outside of the task lock mutex region, so
kono
parents: 0
diff changeset
1290 need a release barrier here to ensure memory
kono
parents: 0
diff changeset
1291 written by child_task->fn above is flushed
kono
parents: 0
diff changeset
1292 before the NULL is written. */
kono
parents: 0
diff changeset
1293 __atomic_store_n (&taskgroup->num_children, 0, MEMMODEL_RELEASE);
kono
parents: 0
diff changeset
1294 }
kono
parents: 0
diff changeset
1295 if (empty && taskgroup->in_taskgroup_wait)
kono
parents: 0
diff changeset
1296 {
kono
parents: 0
diff changeset
1297 taskgroup->in_taskgroup_wait = false;
kono
parents: 0
diff changeset
1298 gomp_sem_post (&taskgroup->taskgroup_sem);
kono
parents: 0
diff changeset
1299 }
kono
parents: 0
diff changeset
1300 }
kono
parents: 0
diff changeset
1301
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303 gomp_barrier_handle_tasks (gomp_barrier_state_t state)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305 struct gomp_thread *thr = gomp_thread ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 struct gomp_team *team = thr->ts.team;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 struct gomp_task *task = thr->task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 struct gomp_task *child_task = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 struct gomp_task *to_free = NULL;
111
kono
parents: 0
diff changeset
1310 int do_wake = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1311
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1312 gomp_mutex_lock (&team->task_lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313 if (gomp_barrier_last_thread (state))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1314 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1315 if (team->task_count == 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1316 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1317 gomp_team_barrier_done (&team->barrier, state);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1318 gomp_mutex_unlock (&team->task_lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1319 gomp_team_barrier_wake (&team->barrier, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1320 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1321 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1322 gomp_team_barrier_set_waiting_for_tasks (&team->barrier);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1323 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1324
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1325 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1326 {
111
kono
parents: 0
diff changeset
1327 bool cancelled = false;
kono
parents: 0
diff changeset
1328 if (!priority_queue_empty_p (&team->task_queue, MEMMODEL_RELAXED))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 {
111
kono
parents: 0
diff changeset
1330 bool ignored;
kono
parents: 0
diff changeset
1331 child_task
kono
parents: 0
diff changeset
1332 = priority_queue_next_task (PQ_TEAM, &team->task_queue,
kono
parents: 0
diff changeset
1333 PQ_IGNORED, NULL,
kono
parents: 0
diff changeset
1334 &ignored);
kono
parents: 0
diff changeset
1335 cancelled = gomp_task_run_pre (child_task, child_task->parent,
kono
parents: 0
diff changeset
1336 team);
kono
parents: 0
diff changeset
1337 if (__builtin_expect (cancelled, 0))
kono
parents: 0
diff changeset
1338 {
kono
parents: 0
diff changeset
1339 if (to_free)
kono
parents: 0
diff changeset
1340 {
kono
parents: 0
diff changeset
1341 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1342 free (to_free);
kono
parents: 0
diff changeset
1343 to_free = NULL;
kono
parents: 0
diff changeset
1344 }
kono
parents: 0
diff changeset
1345 goto finish_cancelled;
kono
parents: 0
diff changeset
1346 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1347 team->task_running_count++;
111
kono
parents: 0
diff changeset
1348 child_task->in_tied_task = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1349 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1350 gomp_mutex_unlock (&team->task_lock);
111
kono
parents: 0
diff changeset
1351 if (do_wake)
kono
parents: 0
diff changeset
1352 {
kono
parents: 0
diff changeset
1353 gomp_team_barrier_wake (&team->barrier, do_wake);
kono
parents: 0
diff changeset
1354 do_wake = 0;
kono
parents: 0
diff changeset
1355 }
kono
parents: 0
diff changeset
1356 if (to_free)
kono
parents: 0
diff changeset
1357 {
kono
parents: 0
diff changeset
1358 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1359 free (to_free);
kono
parents: 0
diff changeset
1360 to_free = NULL;
kono
parents: 0
diff changeset
1361 }
kono
parents: 0
diff changeset
1362 if (child_task)
kono
parents: 0
diff changeset
1363 {
kono
parents: 0
diff changeset
1364 thr->task = child_task;
kono
parents: 0
diff changeset
1365 if (__builtin_expect (child_task->fn == NULL, 0))
kono
parents: 0
diff changeset
1366 {
kono
parents: 0
diff changeset
1367 if (gomp_target_task_fn (child_task->fn_data))
kono
parents: 0
diff changeset
1368 {
kono
parents: 0
diff changeset
1369 thr->task = task;
kono
parents: 0
diff changeset
1370 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1371 child_task->kind = GOMP_TASK_ASYNC_RUNNING;
kono
parents: 0
diff changeset
1372 team->task_running_count--;
kono
parents: 0
diff changeset
1373 struct gomp_target_task *ttask
kono
parents: 0
diff changeset
1374 = (struct gomp_target_task *) child_task->fn_data;
kono
parents: 0
diff changeset
1375 /* If GOMP_PLUGIN_target_task_completion has run already
kono
parents: 0
diff changeset
1376 in between gomp_target_task_fn and the mutex lock,
kono
parents: 0
diff changeset
1377 perform the requeuing here. */
kono
parents: 0
diff changeset
1378 if (ttask->state == GOMP_TARGET_TASK_FINISHED)
kono
parents: 0
diff changeset
1379 gomp_target_task_completion (team, child_task);
kono
parents: 0
diff changeset
1380 else
kono
parents: 0
diff changeset
1381 ttask->state = GOMP_TARGET_TASK_RUNNING;
kono
parents: 0
diff changeset
1382 child_task = NULL;
kono
parents: 0
diff changeset
1383 continue;
kono
parents: 0
diff changeset
1384 }
kono
parents: 0
diff changeset
1385 }
kono
parents: 0
diff changeset
1386 else
kono
parents: 0
diff changeset
1387 child_task->fn (child_task->fn_data);
kono
parents: 0
diff changeset
1388 thr->task = task;
kono
parents: 0
diff changeset
1389 }
kono
parents: 0
diff changeset
1390 else
kono
parents: 0
diff changeset
1391 return;
kono
parents: 0
diff changeset
1392 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1393 if (child_task)
kono
parents: 0
diff changeset
1394 {
kono
parents: 0
diff changeset
1395 finish_cancelled:;
kono
parents: 0
diff changeset
1396 size_t new_tasks
kono
parents: 0
diff changeset
1397 = gomp_task_run_post_handle_depend (child_task, team);
kono
parents: 0
diff changeset
1398 gomp_task_run_post_remove_parent (child_task);
kono
parents: 0
diff changeset
1399 gomp_clear_parent (&child_task->children_queue);
kono
parents: 0
diff changeset
1400 gomp_task_run_post_remove_taskgroup (child_task);
kono
parents: 0
diff changeset
1401 to_free = child_task;
kono
parents: 0
diff changeset
1402 child_task = NULL;
kono
parents: 0
diff changeset
1403 if (!cancelled)
kono
parents: 0
diff changeset
1404 team->task_running_count--;
kono
parents: 0
diff changeset
1405 if (new_tasks > 1)
kono
parents: 0
diff changeset
1406 {
kono
parents: 0
diff changeset
1407 do_wake = team->nthreads - team->task_running_count;
kono
parents: 0
diff changeset
1408 if (do_wake > new_tasks)
kono
parents: 0
diff changeset
1409 do_wake = new_tasks;
kono
parents: 0
diff changeset
1410 }
kono
parents: 0
diff changeset
1411 if (--team->task_count == 0
kono
parents: 0
diff changeset
1412 && gomp_team_barrier_waiting_for_tasks (&team->barrier))
kono
parents: 0
diff changeset
1413 {
kono
parents: 0
diff changeset
1414 gomp_team_barrier_done (&team->barrier, state);
kono
parents: 0
diff changeset
1415 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
1416 gomp_team_barrier_wake (&team->barrier, 0);
kono
parents: 0
diff changeset
1417 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1418 }
kono
parents: 0
diff changeset
1419 }
kono
parents: 0
diff changeset
1420 }
kono
parents: 0
diff changeset
1421 }
kono
parents: 0
diff changeset
1422
kono
parents: 0
diff changeset
1423 /* Called when encountering a taskwait directive.
kono
parents: 0
diff changeset
1424
kono
parents: 0
diff changeset
1425 Wait for all children of the current task. */
kono
parents: 0
diff changeset
1426
kono
parents: 0
diff changeset
1427 void
kono
parents: 0
diff changeset
1428 GOMP_taskwait (void)
kono
parents: 0
diff changeset
1429 {
kono
parents: 0
diff changeset
1430 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
1431 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
1432 struct gomp_task *task = thr->task;
kono
parents: 0
diff changeset
1433 struct gomp_task *child_task = NULL;
kono
parents: 0
diff changeset
1434 struct gomp_task *to_free = NULL;
kono
parents: 0
diff changeset
1435 struct gomp_taskwait taskwait;
kono
parents: 0
diff changeset
1436 int do_wake = 0;
kono
parents: 0
diff changeset
1437
kono
parents: 0
diff changeset
1438 /* The acquire barrier on load of task->children here synchronizes
kono
parents: 0
diff changeset
1439 with the write of a NULL in gomp_task_run_post_remove_parent. It is
kono
parents: 0
diff changeset
1440 not necessary that we synchronize with other non-NULL writes at
kono
parents: 0
diff changeset
1441 this point, but we must ensure that all writes to memory by a
kono
parents: 0
diff changeset
1442 child thread task work function are seen before we exit from
kono
parents: 0
diff changeset
1443 GOMP_taskwait. */
kono
parents: 0
diff changeset
1444 if (task == NULL
kono
parents: 0
diff changeset
1445 || priority_queue_empty_p (&task->children_queue, MEMMODEL_ACQUIRE))
kono
parents: 0
diff changeset
1446 return;
kono
parents: 0
diff changeset
1447
kono
parents: 0
diff changeset
1448 memset (&taskwait, 0, sizeof (taskwait));
kono
parents: 0
diff changeset
1449 bool child_q = false;
kono
parents: 0
diff changeset
1450 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1451 while (1)
kono
parents: 0
diff changeset
1452 {
kono
parents: 0
diff changeset
1453 bool cancelled = false;
kono
parents: 0
diff changeset
1454 if (priority_queue_empty_p (&task->children_queue, MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
1455 {
kono
parents: 0
diff changeset
1456 bool destroy_taskwait = task->taskwait != NULL;
kono
parents: 0
diff changeset
1457 task->taskwait = NULL;
kono
parents: 0
diff changeset
1458 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
1459 if (to_free)
kono
parents: 0
diff changeset
1460 {
kono
parents: 0
diff changeset
1461 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1462 free (to_free);
kono
parents: 0
diff changeset
1463 }
kono
parents: 0
diff changeset
1464 if (destroy_taskwait)
kono
parents: 0
diff changeset
1465 gomp_sem_destroy (&taskwait.taskwait_sem);
kono
parents: 0
diff changeset
1466 return;
kono
parents: 0
diff changeset
1467 }
kono
parents: 0
diff changeset
1468 struct gomp_task *next_task
kono
parents: 0
diff changeset
1469 = priority_queue_next_task (PQ_CHILDREN, &task->children_queue,
kono
parents: 0
diff changeset
1470 PQ_TEAM, &team->task_queue, &child_q);
kono
parents: 0
diff changeset
1471 if (next_task->kind == GOMP_TASK_WAITING)
kono
parents: 0
diff changeset
1472 {
kono
parents: 0
diff changeset
1473 child_task = next_task;
kono
parents: 0
diff changeset
1474 cancelled
kono
parents: 0
diff changeset
1475 = gomp_task_run_pre (child_task, task, team);
kono
parents: 0
diff changeset
1476 if (__builtin_expect (cancelled, 0))
kono
parents: 0
diff changeset
1477 {
kono
parents: 0
diff changeset
1478 if (to_free)
kono
parents: 0
diff changeset
1479 {
kono
parents: 0
diff changeset
1480 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1481 free (to_free);
kono
parents: 0
diff changeset
1482 to_free = NULL;
kono
parents: 0
diff changeset
1483 }
kono
parents: 0
diff changeset
1484 goto finish_cancelled;
kono
parents: 0
diff changeset
1485 }
kono
parents: 0
diff changeset
1486 }
kono
parents: 0
diff changeset
1487 else
kono
parents: 0
diff changeset
1488 {
kono
parents: 0
diff changeset
1489 /* All tasks we are waiting for are either running in other
kono
parents: 0
diff changeset
1490 threads, or they are tasks that have not had their
kono
parents: 0
diff changeset
1491 dependencies met (so they're not even in the queue). Wait
kono
parents: 0
diff changeset
1492 for them. */
kono
parents: 0
diff changeset
1493 if (task->taskwait == NULL)
kono
parents: 0
diff changeset
1494 {
kono
parents: 0
diff changeset
1495 taskwait.in_depend_wait = false;
kono
parents: 0
diff changeset
1496 gomp_sem_init (&taskwait.taskwait_sem, 0);
kono
parents: 0
diff changeset
1497 task->taskwait = &taskwait;
kono
parents: 0
diff changeset
1498 }
kono
parents: 0
diff changeset
1499 taskwait.in_taskwait = true;
kono
parents: 0
diff changeset
1500 }
kono
parents: 0
diff changeset
1501 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
1502 if (do_wake)
kono
parents: 0
diff changeset
1503 {
kono
parents: 0
diff changeset
1504 gomp_team_barrier_wake (&team->barrier, do_wake);
kono
parents: 0
diff changeset
1505 do_wake = 0;
kono
parents: 0
diff changeset
1506 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1507 if (to_free)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1508 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1509 gomp_finish_task (to_free);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1510 free (to_free);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1511 to_free = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1512 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1513 if (child_task)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1514 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1515 thr->task = child_task;
111
kono
parents: 0
diff changeset
1516 if (__builtin_expect (child_task->fn == NULL, 0))
kono
parents: 0
diff changeset
1517 {
kono
parents: 0
diff changeset
1518 if (gomp_target_task_fn (child_task->fn_data))
kono
parents: 0
diff changeset
1519 {
kono
parents: 0
diff changeset
1520 thr->task = task;
kono
parents: 0
diff changeset
1521 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1522 child_task->kind = GOMP_TASK_ASYNC_RUNNING;
kono
parents: 0
diff changeset
1523 struct gomp_target_task *ttask
kono
parents: 0
diff changeset
1524 = (struct gomp_target_task *) child_task->fn_data;
kono
parents: 0
diff changeset
1525 /* If GOMP_PLUGIN_target_task_completion has run already
kono
parents: 0
diff changeset
1526 in between gomp_target_task_fn and the mutex lock,
kono
parents: 0
diff changeset
1527 perform the requeuing here. */
kono
parents: 0
diff changeset
1528 if (ttask->state == GOMP_TARGET_TASK_FINISHED)
kono
parents: 0
diff changeset
1529 gomp_target_task_completion (team, child_task);
kono
parents: 0
diff changeset
1530 else
kono
parents: 0
diff changeset
1531 ttask->state = GOMP_TARGET_TASK_RUNNING;
kono
parents: 0
diff changeset
1532 child_task = NULL;
kono
parents: 0
diff changeset
1533 continue;
kono
parents: 0
diff changeset
1534 }
kono
parents: 0
diff changeset
1535 }
kono
parents: 0
diff changeset
1536 else
kono
parents: 0
diff changeset
1537 child_task->fn (child_task->fn_data);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1538 thr->task = task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1539 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1540 else
111
kono
parents: 0
diff changeset
1541 gomp_sem_wait (&taskwait.taskwait_sem);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1542 gomp_mutex_lock (&team->task_lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1543 if (child_task)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1544 {
111
kono
parents: 0
diff changeset
1545 finish_cancelled:;
kono
parents: 0
diff changeset
1546 size_t new_tasks
kono
parents: 0
diff changeset
1547 = gomp_task_run_post_handle_depend (child_task, team);
kono
parents: 0
diff changeset
1548
kono
parents: 0
diff changeset
1549 if (child_q)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1550 {
111
kono
parents: 0
diff changeset
1551 priority_queue_remove (PQ_CHILDREN, &task->children_queue,
kono
parents: 0
diff changeset
1552 child_task, MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
1553 child_task->pnode[PQ_CHILDREN].next = NULL;
kono
parents: 0
diff changeset
1554 child_task->pnode[PQ_CHILDREN].prev = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1555 }
111
kono
parents: 0
diff changeset
1556
kono
parents: 0
diff changeset
1557 gomp_clear_parent (&child_task->children_queue);
kono
parents: 0
diff changeset
1558
kono
parents: 0
diff changeset
1559 gomp_task_run_post_remove_taskgroup (child_task);
kono
parents: 0
diff changeset
1560
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1561 to_free = child_task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1562 child_task = NULL;
111
kono
parents: 0
diff changeset
1563 team->task_count--;
kono
parents: 0
diff changeset
1564 if (new_tasks > 1)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1565 {
111
kono
parents: 0
diff changeset
1566 do_wake = team->nthreads - team->task_running_count
kono
parents: 0
diff changeset
1567 - !task->in_tied_task;
kono
parents: 0
diff changeset
1568 if (do_wake > new_tasks)
kono
parents: 0
diff changeset
1569 do_wake = new_tasks;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1570 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1571 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1572 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1573 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1574
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1575 /* Called when encountering a taskwait directive with depend clause(s).
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1576 Wait as if it was an mergeable included task construct with empty body. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1577
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1578 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1579 GOMP_taskwait_depend (void **depend)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1580 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1581 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1582 struct gomp_team *team = thr->ts.team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1583
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1584 /* If parallel or taskgroup has been cancelled, return early. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1585 if (__builtin_expect (gomp_cancel_var, 0) && team)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1586 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1587 if (gomp_team_barrier_cancelled (&team->barrier))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1588 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1589 if (thr->task->taskgroup)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1590 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1591 if (thr->task->taskgroup->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1592 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1593 if (thr->task->taskgroup->workshare
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1594 && thr->task->taskgroup->prev
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1595 && thr->task->taskgroup->prev->cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1596 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1597 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1598 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1599
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1600 if (thr->task && thr->task->depend_hash)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1601 gomp_task_maybe_wait_for_dependencies (depend);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1602 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1603
111
kono
parents: 0
diff changeset
1604 /* An undeferred task is about to run. Wait for all tasks that this
kono
parents: 0
diff changeset
1605 undeferred task depends on.
kono
parents: 0
diff changeset
1606
kono
parents: 0
diff changeset
1607 This is done by first putting all known ready dependencies
kono
parents: 0
diff changeset
1608 (dependencies that have their own dependencies met) at the top of
kono
parents: 0
diff changeset
1609 the scheduling queues. Then we iterate through these imminently
kono
parents: 0
diff changeset
1610 ready tasks (and possibly other high priority tasks), and run them.
kono
parents: 0
diff changeset
1611 If we run out of ready dependencies to execute, we either wait for
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1612 the remaining dependencies to finish, or wait for them to get
111
kono
parents: 0
diff changeset
1613 scheduled so we can run them.
kono
parents: 0
diff changeset
1614
kono
parents: 0
diff changeset
1615 DEPEND is as in GOMP_task. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1616
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1617 void
111
kono
parents: 0
diff changeset
1618 gomp_task_maybe_wait_for_dependencies (void **depend)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1619 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1620 struct gomp_thread *thr = gomp_thread ();
111
kono
parents: 0
diff changeset
1621 struct gomp_task *task = thr->task;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1622 struct gomp_team *team = thr->ts.team;
111
kono
parents: 0
diff changeset
1623 struct gomp_task_depend_entry elem, *ent = NULL;
kono
parents: 0
diff changeset
1624 struct gomp_taskwait taskwait;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1625 size_t orig_ndepend = (uintptr_t) depend[0];
111
kono
parents: 0
diff changeset
1626 size_t nout = (uintptr_t) depend[1];
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1627 size_t ndepend = orig_ndepend;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1628 size_t normal = ndepend;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1629 size_t n = 2;
111
kono
parents: 0
diff changeset
1630 size_t i;
kono
parents: 0
diff changeset
1631 size_t num_awaited = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1632 struct gomp_task *child_task = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1633 struct gomp_task *to_free = NULL;
111
kono
parents: 0
diff changeset
1634 int do_wake = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1635
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1636 if (ndepend == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1637 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1638 ndepend = nout;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1639 nout = (uintptr_t) depend[2] + (uintptr_t) depend[3];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1640 normal = nout + (uintptr_t) depend[4];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1641 n = 5;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1642 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1643 gomp_mutex_lock (&team->task_lock);
111
kono
parents: 0
diff changeset
1644 for (i = 0; i < ndepend; i++)
kono
parents: 0
diff changeset
1645 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1646 elem.addr = depend[i + n];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1647 elem.is_in = i >= nout;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1648 if (__builtin_expect (i >= normal, 0))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1649 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1650 void **d = (void **) elem.addr;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1651 switch ((uintptr_t) d[1])
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1652 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1653 case GOMP_DEPEND_IN:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1654 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1655 case GOMP_DEPEND_OUT:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1656 case GOMP_DEPEND_INOUT:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1657 case GOMP_DEPEND_MUTEXINOUTSET:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1658 elem.is_in = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1659 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1660 default:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1661 gomp_fatal ("unknown omp_depend_t dependence type %d",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1662 (int) (uintptr_t) d[1]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1663 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1664 elem.addr = d[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1665 }
111
kono
parents: 0
diff changeset
1666 ent = htab_find (task->depend_hash, &elem);
kono
parents: 0
diff changeset
1667 for (; ent; ent = ent->next)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1668 if (elem.is_in && ent->is_in)
111
kono
parents: 0
diff changeset
1669 continue;
kono
parents: 0
diff changeset
1670 else
kono
parents: 0
diff changeset
1671 {
kono
parents: 0
diff changeset
1672 struct gomp_task *tsk = ent->task;
kono
parents: 0
diff changeset
1673 if (!tsk->parent_depends_on)
kono
parents: 0
diff changeset
1674 {
kono
parents: 0
diff changeset
1675 tsk->parent_depends_on = true;
kono
parents: 0
diff changeset
1676 ++num_awaited;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1677 /* If dependency TSK itself has no dependencies and is
111
kono
parents: 0
diff changeset
1678 ready to run, move it up front so that we run it as
kono
parents: 0
diff changeset
1679 soon as possible. */
kono
parents: 0
diff changeset
1680 if (tsk->num_dependees == 0 && tsk->kind == GOMP_TASK_WAITING)
kono
parents: 0
diff changeset
1681 priority_queue_upgrade_task (tsk, task);
kono
parents: 0
diff changeset
1682 }
kono
parents: 0
diff changeset
1683 }
kono
parents: 0
diff changeset
1684 }
kono
parents: 0
diff changeset
1685 if (num_awaited == 0)
kono
parents: 0
diff changeset
1686 {
kono
parents: 0
diff changeset
1687 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
1688 return;
kono
parents: 0
diff changeset
1689 }
kono
parents: 0
diff changeset
1690
kono
parents: 0
diff changeset
1691 memset (&taskwait, 0, sizeof (taskwait));
kono
parents: 0
diff changeset
1692 taskwait.n_depend = num_awaited;
kono
parents: 0
diff changeset
1693 gomp_sem_init (&taskwait.taskwait_sem, 0);
kono
parents: 0
diff changeset
1694 task->taskwait = &taskwait;
kono
parents: 0
diff changeset
1695
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1696 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1697 {
111
kono
parents: 0
diff changeset
1698 bool cancelled = false;
kono
parents: 0
diff changeset
1699 if (taskwait.n_depend == 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1700 {
111
kono
parents: 0
diff changeset
1701 task->taskwait = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1702 gomp_mutex_unlock (&team->task_lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1703 if (to_free)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1704 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1705 gomp_finish_task (to_free);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1706 free (to_free);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1707 }
111
kono
parents: 0
diff changeset
1708 gomp_sem_destroy (&taskwait.taskwait_sem);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1709 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1710 }
111
kono
parents: 0
diff changeset
1711
kono
parents: 0
diff changeset
1712 /* Theoretically when we have multiple priorities, we should
kono
parents: 0
diff changeset
1713 chose between the highest priority item in
kono
parents: 0
diff changeset
1714 task->children_queue and team->task_queue here, so we should
kono
parents: 0
diff changeset
1715 use priority_queue_next_task(). However, since we are
kono
parents: 0
diff changeset
1716 running an undeferred task, perhaps that makes all tasks it
kono
parents: 0
diff changeset
1717 depends on undeferred, thus a priority of INF? This would
kono
parents: 0
diff changeset
1718 make it unnecessary to take anything into account here,
kono
parents: 0
diff changeset
1719 but the dependencies.
kono
parents: 0
diff changeset
1720
kono
parents: 0
diff changeset
1721 On the other hand, if we want to use priority_queue_next_task(),
kono
parents: 0
diff changeset
1722 care should be taken to only use priority_queue_remove()
kono
parents: 0
diff changeset
1723 below if the task was actually removed from the children
kono
parents: 0
diff changeset
1724 queue. */
kono
parents: 0
diff changeset
1725 bool ignored;
kono
parents: 0
diff changeset
1726 struct gomp_task *next_task
kono
parents: 0
diff changeset
1727 = priority_queue_next_task (PQ_CHILDREN, &task->children_queue,
kono
parents: 0
diff changeset
1728 PQ_IGNORED, NULL, &ignored);
kono
parents: 0
diff changeset
1729
kono
parents: 0
diff changeset
1730 if (next_task->kind == GOMP_TASK_WAITING)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1731 {
111
kono
parents: 0
diff changeset
1732 child_task = next_task;
kono
parents: 0
diff changeset
1733 cancelled
kono
parents: 0
diff changeset
1734 = gomp_task_run_pre (child_task, task, team);
kono
parents: 0
diff changeset
1735 if (__builtin_expect (cancelled, 0))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1736 {
111
kono
parents: 0
diff changeset
1737 if (to_free)
kono
parents: 0
diff changeset
1738 {
kono
parents: 0
diff changeset
1739 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1740 free (to_free);
kono
parents: 0
diff changeset
1741 to_free = NULL;
kono
parents: 0
diff changeset
1742 }
kono
parents: 0
diff changeset
1743 goto finish_cancelled;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1744 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1745 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1746 else
111
kono
parents: 0
diff changeset
1747 /* All tasks we are waiting for are either running in other
kono
parents: 0
diff changeset
1748 threads, or they are tasks that have not had their
kono
parents: 0
diff changeset
1749 dependencies met (so they're not even in the queue). Wait
kono
parents: 0
diff changeset
1750 for them. */
kono
parents: 0
diff changeset
1751 taskwait.in_depend_wait = true;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1752 gomp_mutex_unlock (&team->task_lock);
111
kono
parents: 0
diff changeset
1753 if (do_wake)
kono
parents: 0
diff changeset
1754 {
kono
parents: 0
diff changeset
1755 gomp_team_barrier_wake (&team->barrier, do_wake);
kono
parents: 0
diff changeset
1756 do_wake = 0;
kono
parents: 0
diff changeset
1757 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1758 if (to_free)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1759 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1760 gomp_finish_task (to_free);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1761 free (to_free);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1762 to_free = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1763 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1764 if (child_task)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1765 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1766 thr->task = child_task;
111
kono
parents: 0
diff changeset
1767 if (__builtin_expect (child_task->fn == NULL, 0))
kono
parents: 0
diff changeset
1768 {
kono
parents: 0
diff changeset
1769 if (gomp_target_task_fn (child_task->fn_data))
kono
parents: 0
diff changeset
1770 {
kono
parents: 0
diff changeset
1771 thr->task = task;
kono
parents: 0
diff changeset
1772 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1773 child_task->kind = GOMP_TASK_ASYNC_RUNNING;
kono
parents: 0
diff changeset
1774 struct gomp_target_task *ttask
kono
parents: 0
diff changeset
1775 = (struct gomp_target_task *) child_task->fn_data;
kono
parents: 0
diff changeset
1776 /* If GOMP_PLUGIN_target_task_completion has run already
kono
parents: 0
diff changeset
1777 in between gomp_target_task_fn and the mutex lock,
kono
parents: 0
diff changeset
1778 perform the requeuing here. */
kono
parents: 0
diff changeset
1779 if (ttask->state == GOMP_TARGET_TASK_FINISHED)
kono
parents: 0
diff changeset
1780 gomp_target_task_completion (team, child_task);
kono
parents: 0
diff changeset
1781 else
kono
parents: 0
diff changeset
1782 ttask->state = GOMP_TARGET_TASK_RUNNING;
kono
parents: 0
diff changeset
1783 child_task = NULL;
kono
parents: 0
diff changeset
1784 continue;
kono
parents: 0
diff changeset
1785 }
kono
parents: 0
diff changeset
1786 }
kono
parents: 0
diff changeset
1787 else
kono
parents: 0
diff changeset
1788 child_task->fn (child_task->fn_data);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1789 thr->task = task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1790 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1791 else
111
kono
parents: 0
diff changeset
1792 gomp_sem_wait (&taskwait.taskwait_sem);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1793 gomp_mutex_lock (&team->task_lock);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1794 if (child_task)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1795 {
111
kono
parents: 0
diff changeset
1796 finish_cancelled:;
kono
parents: 0
diff changeset
1797 size_t new_tasks
kono
parents: 0
diff changeset
1798 = gomp_task_run_post_handle_depend (child_task, team);
kono
parents: 0
diff changeset
1799 if (child_task->parent_depends_on)
kono
parents: 0
diff changeset
1800 --taskwait.n_depend;
kono
parents: 0
diff changeset
1801
kono
parents: 0
diff changeset
1802 priority_queue_remove (PQ_CHILDREN, &task->children_queue,
kono
parents: 0
diff changeset
1803 child_task, MEMMODEL_RELAXED);
kono
parents: 0
diff changeset
1804 child_task->pnode[PQ_CHILDREN].next = NULL;
kono
parents: 0
diff changeset
1805 child_task->pnode[PQ_CHILDREN].prev = NULL;
kono
parents: 0
diff changeset
1806
kono
parents: 0
diff changeset
1807 gomp_clear_parent (&child_task->children_queue);
kono
parents: 0
diff changeset
1808 gomp_task_run_post_remove_taskgroup (child_task);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1809 to_free = child_task;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1810 child_task = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1811 team->task_count--;
111
kono
parents: 0
diff changeset
1812 if (new_tasks > 1)
kono
parents: 0
diff changeset
1813 {
kono
parents: 0
diff changeset
1814 do_wake = team->nthreads - team->task_running_count
kono
parents: 0
diff changeset
1815 - !task->in_tied_task;
kono
parents: 0
diff changeset
1816 if (do_wake > new_tasks)
kono
parents: 0
diff changeset
1817 do_wake = new_tasks;
kono
parents: 0
diff changeset
1818 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1819 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1820 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1821 }
111
kono
parents: 0
diff changeset
1822
kono
parents: 0
diff changeset
1823 /* Called when encountering a taskyield directive. */
kono
parents: 0
diff changeset
1824
kono
parents: 0
diff changeset
1825 void
kono
parents: 0
diff changeset
1826 GOMP_taskyield (void)
kono
parents: 0
diff changeset
1827 {
kono
parents: 0
diff changeset
1828 /* Nothing at the moment. */
kono
parents: 0
diff changeset
1829 }
kono
parents: 0
diff changeset
1830
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1831 static inline struct gomp_taskgroup *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1832 gomp_taskgroup_init (struct gomp_taskgroup *prev)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1833 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1834 struct gomp_taskgroup *taskgroup
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1835 = gomp_malloc (sizeof (struct gomp_taskgroup));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1836 taskgroup->prev = prev;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1837 priority_queue_init (&taskgroup->taskgroup_queue);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1838 taskgroup->reductions = prev ? prev->reductions : NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1839 taskgroup->in_taskgroup_wait = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1840 taskgroup->cancelled = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1841 taskgroup->workshare = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1842 taskgroup->num_children = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1843 gomp_sem_init (&taskgroup->taskgroup_sem, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1844 return taskgroup;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1845 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1846
111
kono
parents: 0
diff changeset
1847 void
kono
parents: 0
diff changeset
1848 GOMP_taskgroup_start (void)
kono
parents: 0
diff changeset
1849 {
kono
parents: 0
diff changeset
1850 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
1851 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
1852 struct gomp_task *task = thr->task;
kono
parents: 0
diff changeset
1853
kono
parents: 0
diff changeset
1854 /* If team is NULL, all tasks are executed as
kono
parents: 0
diff changeset
1855 GOMP_TASK_UNDEFERRED tasks and thus all children tasks of
kono
parents: 0
diff changeset
1856 taskgroup and their descendant tasks will be finished
kono
parents: 0
diff changeset
1857 by the time GOMP_taskgroup_end is called. */
kono
parents: 0
diff changeset
1858 if (team == NULL)
kono
parents: 0
diff changeset
1859 return;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1860 task->taskgroup = gomp_taskgroup_init (task->taskgroup);
111
kono
parents: 0
diff changeset
1861 }
kono
parents: 0
diff changeset
1862
kono
parents: 0
diff changeset
1863 void
kono
parents: 0
diff changeset
1864 GOMP_taskgroup_end (void)
kono
parents: 0
diff changeset
1865 {
kono
parents: 0
diff changeset
1866 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
1867 struct gomp_team *team = thr->ts.team;
kono
parents: 0
diff changeset
1868 struct gomp_task *task = thr->task;
kono
parents: 0
diff changeset
1869 struct gomp_taskgroup *taskgroup;
kono
parents: 0
diff changeset
1870 struct gomp_task *child_task = NULL;
kono
parents: 0
diff changeset
1871 struct gomp_task *to_free = NULL;
kono
parents: 0
diff changeset
1872 int do_wake = 0;
kono
parents: 0
diff changeset
1873
kono
parents: 0
diff changeset
1874 if (team == NULL)
kono
parents: 0
diff changeset
1875 return;
kono
parents: 0
diff changeset
1876 taskgroup = task->taskgroup;
kono
parents: 0
diff changeset
1877 if (__builtin_expect (taskgroup == NULL, 0)
kono
parents: 0
diff changeset
1878 && thr->ts.level == 0)
kono
parents: 0
diff changeset
1879 {
kono
parents: 0
diff changeset
1880 /* This can happen if GOMP_taskgroup_start is called when
kono
parents: 0
diff changeset
1881 thr->ts.team == NULL, but inside of the taskgroup there
kono
parents: 0
diff changeset
1882 is #pragma omp target nowait that creates an implicit
kono
parents: 0
diff changeset
1883 team with a single thread. In this case, we want to wait
kono
parents: 0
diff changeset
1884 for all outstanding tasks in this team. */
kono
parents: 0
diff changeset
1885 gomp_team_barrier_wait (&team->barrier);
kono
parents: 0
diff changeset
1886 return;
kono
parents: 0
diff changeset
1887 }
kono
parents: 0
diff changeset
1888
kono
parents: 0
diff changeset
1889 /* The acquire barrier on load of taskgroup->num_children here
kono
parents: 0
diff changeset
1890 synchronizes with the write of 0 in gomp_task_run_post_remove_taskgroup.
kono
parents: 0
diff changeset
1891 It is not necessary that we synchronize with other non-0 writes at
kono
parents: 0
diff changeset
1892 this point, but we must ensure that all writes to memory by a
kono
parents: 0
diff changeset
1893 child thread task work function are seen before we exit from
kono
parents: 0
diff changeset
1894 GOMP_taskgroup_end. */
kono
parents: 0
diff changeset
1895 if (__atomic_load_n (&taskgroup->num_children, MEMMODEL_ACQUIRE) == 0)
kono
parents: 0
diff changeset
1896 goto finish;
kono
parents: 0
diff changeset
1897
kono
parents: 0
diff changeset
1898 bool unused;
kono
parents: 0
diff changeset
1899 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1900 while (1)
kono
parents: 0
diff changeset
1901 {
kono
parents: 0
diff changeset
1902 bool cancelled = false;
kono
parents: 0
diff changeset
1903 if (priority_queue_empty_p (&taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
1904 MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
1905 {
kono
parents: 0
diff changeset
1906 if (taskgroup->num_children)
kono
parents: 0
diff changeset
1907 {
kono
parents: 0
diff changeset
1908 if (priority_queue_empty_p (&task->children_queue,
kono
parents: 0
diff changeset
1909 MEMMODEL_RELAXED))
kono
parents: 0
diff changeset
1910 goto do_wait;
kono
parents: 0
diff changeset
1911 child_task
kono
parents: 0
diff changeset
1912 = priority_queue_next_task (PQ_CHILDREN, &task->children_queue,
kono
parents: 0
diff changeset
1913 PQ_TEAM, &team->task_queue,
kono
parents: 0
diff changeset
1914 &unused);
kono
parents: 0
diff changeset
1915 }
kono
parents: 0
diff changeset
1916 else
kono
parents: 0
diff changeset
1917 {
kono
parents: 0
diff changeset
1918 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
1919 if (to_free)
kono
parents: 0
diff changeset
1920 {
kono
parents: 0
diff changeset
1921 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1922 free (to_free);
kono
parents: 0
diff changeset
1923 }
kono
parents: 0
diff changeset
1924 goto finish;
kono
parents: 0
diff changeset
1925 }
kono
parents: 0
diff changeset
1926 }
kono
parents: 0
diff changeset
1927 else
kono
parents: 0
diff changeset
1928 child_task
kono
parents: 0
diff changeset
1929 = priority_queue_next_task (PQ_TASKGROUP, &taskgroup->taskgroup_queue,
kono
parents: 0
diff changeset
1930 PQ_TEAM, &team->task_queue, &unused);
kono
parents: 0
diff changeset
1931 if (child_task->kind == GOMP_TASK_WAITING)
kono
parents: 0
diff changeset
1932 {
kono
parents: 0
diff changeset
1933 cancelled
kono
parents: 0
diff changeset
1934 = gomp_task_run_pre (child_task, child_task->parent, team);
kono
parents: 0
diff changeset
1935 if (__builtin_expect (cancelled, 0))
kono
parents: 0
diff changeset
1936 {
kono
parents: 0
diff changeset
1937 if (to_free)
kono
parents: 0
diff changeset
1938 {
kono
parents: 0
diff changeset
1939 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1940 free (to_free);
kono
parents: 0
diff changeset
1941 to_free = NULL;
kono
parents: 0
diff changeset
1942 }
kono
parents: 0
diff changeset
1943 goto finish_cancelled;
kono
parents: 0
diff changeset
1944 }
kono
parents: 0
diff changeset
1945 }
kono
parents: 0
diff changeset
1946 else
kono
parents: 0
diff changeset
1947 {
kono
parents: 0
diff changeset
1948 child_task = NULL;
kono
parents: 0
diff changeset
1949 do_wait:
kono
parents: 0
diff changeset
1950 /* All tasks we are waiting for are either running in other
kono
parents: 0
diff changeset
1951 threads, or they are tasks that have not had their
kono
parents: 0
diff changeset
1952 dependencies met (so they're not even in the queue). Wait
kono
parents: 0
diff changeset
1953 for them. */
kono
parents: 0
diff changeset
1954 taskgroup->in_taskgroup_wait = true;
kono
parents: 0
diff changeset
1955 }
kono
parents: 0
diff changeset
1956 gomp_mutex_unlock (&team->task_lock);
kono
parents: 0
diff changeset
1957 if (do_wake)
kono
parents: 0
diff changeset
1958 {
kono
parents: 0
diff changeset
1959 gomp_team_barrier_wake (&team->barrier, do_wake);
kono
parents: 0
diff changeset
1960 do_wake = 0;
kono
parents: 0
diff changeset
1961 }
kono
parents: 0
diff changeset
1962 if (to_free)
kono
parents: 0
diff changeset
1963 {
kono
parents: 0
diff changeset
1964 gomp_finish_task (to_free);
kono
parents: 0
diff changeset
1965 free (to_free);
kono
parents: 0
diff changeset
1966 to_free = NULL;
kono
parents: 0
diff changeset
1967 }
kono
parents: 0
diff changeset
1968 if (child_task)
kono
parents: 0
diff changeset
1969 {
kono
parents: 0
diff changeset
1970 thr->task = child_task;
kono
parents: 0
diff changeset
1971 if (__builtin_expect (child_task->fn == NULL, 0))
kono
parents: 0
diff changeset
1972 {
kono
parents: 0
diff changeset
1973 if (gomp_target_task_fn (child_task->fn_data))
kono
parents: 0
diff changeset
1974 {
kono
parents: 0
diff changeset
1975 thr->task = task;
kono
parents: 0
diff changeset
1976 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1977 child_task->kind = GOMP_TASK_ASYNC_RUNNING;
kono
parents: 0
diff changeset
1978 struct gomp_target_task *ttask
kono
parents: 0
diff changeset
1979 = (struct gomp_target_task *) child_task->fn_data;
kono
parents: 0
diff changeset
1980 /* If GOMP_PLUGIN_target_task_completion has run already
kono
parents: 0
diff changeset
1981 in between gomp_target_task_fn and the mutex lock,
kono
parents: 0
diff changeset
1982 perform the requeuing here. */
kono
parents: 0
diff changeset
1983 if (ttask->state == GOMP_TARGET_TASK_FINISHED)
kono
parents: 0
diff changeset
1984 gomp_target_task_completion (team, child_task);
kono
parents: 0
diff changeset
1985 else
kono
parents: 0
diff changeset
1986 ttask->state = GOMP_TARGET_TASK_RUNNING;
kono
parents: 0
diff changeset
1987 child_task = NULL;
kono
parents: 0
diff changeset
1988 continue;
kono
parents: 0
diff changeset
1989 }
kono
parents: 0
diff changeset
1990 }
kono
parents: 0
diff changeset
1991 else
kono
parents: 0
diff changeset
1992 child_task->fn (child_task->fn_data);
kono
parents: 0
diff changeset
1993 thr->task = task;
kono
parents: 0
diff changeset
1994 }
kono
parents: 0
diff changeset
1995 else
kono
parents: 0
diff changeset
1996 gomp_sem_wait (&taskgroup->taskgroup_sem);
kono
parents: 0
diff changeset
1997 gomp_mutex_lock (&team->task_lock);
kono
parents: 0
diff changeset
1998 if (child_task)
kono
parents: 0
diff changeset
1999 {
kono
parents: 0
diff changeset
2000 finish_cancelled:;
kono
parents: 0
diff changeset
2001 size_t new_tasks
kono
parents: 0
diff changeset
2002 = gomp_task_run_post_handle_depend (child_task, team);
kono
parents: 0
diff changeset
2003 gomp_task_run_post_remove_parent (child_task);
kono
parents: 0
diff changeset
2004 gomp_clear_parent (&child_task->children_queue);
kono
parents: 0
diff changeset
2005 gomp_task_run_post_remove_taskgroup (child_task);
kono
parents: 0
diff changeset
2006 to_free = child_task;
kono
parents: 0
diff changeset
2007 child_task = NULL;
kono
parents: 0
diff changeset
2008 team->task_count--;
kono
parents: 0
diff changeset
2009 if (new_tasks > 1)
kono
parents: 0
diff changeset
2010 {
kono
parents: 0
diff changeset
2011 do_wake = team->nthreads - team->task_running_count
kono
parents: 0
diff changeset
2012 - !task->in_tied_task;
kono
parents: 0
diff changeset
2013 if (do_wake > new_tasks)
kono
parents: 0
diff changeset
2014 do_wake = new_tasks;
kono
parents: 0
diff changeset
2015 }
kono
parents: 0
diff changeset
2016 }
kono
parents: 0
diff changeset
2017 }
kono
parents: 0
diff changeset
2018
kono
parents: 0
diff changeset
2019 finish:
kono
parents: 0
diff changeset
2020 task->taskgroup = taskgroup->prev;
kono
parents: 0
diff changeset
2021 gomp_sem_destroy (&taskgroup->taskgroup_sem);
kono
parents: 0
diff changeset
2022 free (taskgroup);
kono
parents: 0
diff changeset
2023 }
kono
parents: 0
diff changeset
2024
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2025 static inline __attribute__((always_inline)) void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2026 gomp_reduction_register (uintptr_t *data, uintptr_t *old, uintptr_t *orig,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2027 unsigned nthreads)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2028 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2029 size_t total_cnt = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2030 uintptr_t *d = data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2031 struct htab *old_htab = NULL, *new_htab;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2032 do
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2033 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2034 if (__builtin_expect (orig != NULL, 0))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2035 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2036 /* For worksharing task reductions, memory has been allocated
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2037 already by some other thread that encountered the construct
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2038 earlier. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2039 d[2] = orig[2];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2040 d[6] = orig[6];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2041 orig = (uintptr_t *) orig[4];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2042 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2043 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2044 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2045 size_t sz = d[1] * nthreads;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2046 /* Should use omp_alloc if d[3] is not -1. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2047 void *ptr = gomp_aligned_alloc (d[2], sz);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2048 memset (ptr, '\0', sz);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2049 d[2] = (uintptr_t) ptr;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2050 d[6] = d[2] + sz;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2051 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2052 d[5] = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2053 total_cnt += d[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2054 if (d[4] == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2055 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2056 d[4] = (uintptr_t) old;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2057 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2058 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2059 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2060 d = (uintptr_t *) d[4];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2061 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2062 while (1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2063 if (old && old[5])
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2064 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2065 old_htab = (struct htab *) old[5];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2066 total_cnt += htab_elements (old_htab);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2067 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2068 new_htab = htab_create (total_cnt);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2069 if (old_htab)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2070 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2071 /* Copy old hash table, like in htab_expand. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2072 hash_entry_type *p, *olimit;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2073 new_htab->n_elements = htab_elements (old_htab);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2074 olimit = old_htab->entries + old_htab->size;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2075 p = old_htab->entries;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2076 do
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2077 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2078 hash_entry_type x = *p;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2079 if (x != HTAB_EMPTY_ENTRY && x != HTAB_DELETED_ENTRY)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2080 *find_empty_slot_for_expand (new_htab, htab_hash (x)) = x;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2081 p++;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2082 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2083 while (p < olimit);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2084 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2085 d = data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2086 do
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2087 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2088 size_t j;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2089 for (j = 0; j < d[0]; ++j)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2090 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2091 uintptr_t *p = d + 7 + j * 3;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2092 p[2] = (uintptr_t) d;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2093 /* Ugly hack, hash_entry_type is defined for the task dependencies,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2094 which hash on the first element which is a pointer. We need
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2095 to hash also on the first sizeof (uintptr_t) bytes which contain
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2096 a pointer. Hide the cast from the compiler. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2097 hash_entry_type n;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2098 __asm ("" : "=g" (n) : "0" (p));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2099 *htab_find_slot (&new_htab, n, INSERT) = n;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2100 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2101 if (d[4] == (uintptr_t) old)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2102 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2103 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2104 d = (uintptr_t *) d[4];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2105 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2106 while (1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2107 d[5] = (uintptr_t) new_htab;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2108 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2109
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2110 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2111 gomp_create_artificial_team (void)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2112 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2113 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2114 struct gomp_task_icv *icv;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2115 struct gomp_team *team = gomp_new_team (1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2116 struct gomp_task *task = thr->task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2117 icv = task ? &task->icv : &gomp_global_icv;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2118 team->prev_ts = thr->ts;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2119 thr->ts.team = team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2120 thr->ts.team_id = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2121 thr->ts.work_share = &team->work_shares[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2122 thr->ts.last_work_share = NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2123 #ifdef HAVE_SYNC_BUILTINS
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2124 thr->ts.single_count = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2125 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2126 thr->ts.static_trip = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2127 thr->task = &team->implicit_task[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2128 gomp_init_task (thr->task, NULL, icv);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2129 if (task)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2130 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2131 thr->task = task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2132 gomp_end_task ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2133 free (task);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2134 thr->task = &team->implicit_task[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2135 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2136 #ifdef LIBGOMP_USE_PTHREADS
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2137 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2138 pthread_setspecific (gomp_thread_destructor, thr);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2139 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2140 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2141
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2142 /* The format of data is:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2143 data[0] cnt
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2144 data[1] size
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2145 data[2] alignment (on output array pointer)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2146 data[3] allocator (-1 if malloc allocator)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2147 data[4] next pointer
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2148 data[5] used internally (htab pointer)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2149 data[6] used internally (end of array)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2150 cnt times
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2151 ent[0] address
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2152 ent[1] offset
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2153 ent[2] used internally (pointer to data[0])
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2154 The entries are sorted by increasing offset, so that a binary
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2155 search can be performed. Normally, data[8] is 0, exception is
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2156 for worksharing construct task reductions in cancellable parallel,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2157 where at offset 0 there should be space for a pointer and an integer
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2158 which are used internally. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2159
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2160 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2161 GOMP_taskgroup_reduction_register (uintptr_t *data)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2162 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2163 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2164 struct gomp_team *team = thr->ts.team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2165 struct gomp_task *task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2166 unsigned nthreads;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2167 if (__builtin_expect (team == NULL, 0))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2168 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2169 /* The task reduction code needs a team and task, so for
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2170 orphaned taskgroups just create the implicit team. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2171 gomp_create_artificial_team ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2172 ialias_call (GOMP_taskgroup_start) ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2173 team = thr->ts.team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2174 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2175 nthreads = team->nthreads;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2176 task = thr->task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2177 gomp_reduction_register (data, task->taskgroup->reductions, NULL, nthreads);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2178 task->taskgroup->reductions = data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2179 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2180
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2181 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2182 GOMP_taskgroup_reduction_unregister (uintptr_t *data)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2183 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2184 uintptr_t *d = data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2185 htab_free ((struct htab *) data[5]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2186 do
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2187 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2188 gomp_aligned_free ((void *) d[2]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2189 d = (uintptr_t *) d[4];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2190 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2191 while (d && !d[5]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2192 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2193 ialias (GOMP_taskgroup_reduction_unregister)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2194
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2195 /* For i = 0 to cnt-1, remap ptrs[i] which is either address of the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2196 original list item or address of previously remapped original list
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2197 item to address of the private copy, store that to ptrs[i].
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2198 For i < cntorig, additionally set ptrs[cnt+i] to the address of
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2199 the original list item. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2200
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2201 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2202 GOMP_task_reduction_remap (size_t cnt, size_t cntorig, void **ptrs)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2203 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2204 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2205 struct gomp_task *task = thr->task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2206 unsigned id = thr->ts.team_id;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2207 uintptr_t *data = task->taskgroup->reductions;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2208 uintptr_t *d;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2209 struct htab *reduction_htab = (struct htab *) data[5];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2210 size_t i;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2211 for (i = 0; i < cnt; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2212 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2213 hash_entry_type ent, n;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2214 __asm ("" : "=g" (ent) : "0" (ptrs + i));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2215 n = htab_find (reduction_htab, ent);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2216 if (n)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2217 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2218 uintptr_t *p;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2219 __asm ("" : "=g" (p) : "0" (n));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2220 /* At this point, p[0] should be equal to (uintptr_t) ptrs[i],
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2221 p[1] is the offset within the allocated chunk for each
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2222 thread, p[2] is the array registered with
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2223 GOMP_taskgroup_reduction_register, d[2] is the base of the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2224 allocated memory and d[1] is the size of the allocated chunk
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2225 for one thread. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2226 d = (uintptr_t *) p[2];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2227 ptrs[i] = (void *) (d[2] + id * d[1] + p[1]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2228 if (__builtin_expect (i < cntorig, 0))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2229 ptrs[cnt + i] = (void *) p[0];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2230 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2231 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2232 d = data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2233 while (d != NULL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2234 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2235 if ((uintptr_t) ptrs[i] >= d[2] && (uintptr_t) ptrs[i] < d[6])
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2236 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2237 d = (uintptr_t *) d[4];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2238 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2239 if (d == NULL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2240 gomp_fatal ("couldn't find matching task_reduction or reduction with "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2241 "task modifier for %p", ptrs[i]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2242 uintptr_t off = ((uintptr_t) ptrs[i] - d[2]) % d[1];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2243 ptrs[i] = (void *) (d[2] + id * d[1] + off);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2244 if (__builtin_expect (i < cntorig, 0))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2245 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2246 size_t lo = 0, hi = d[0] - 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2247 while (lo <= hi)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2248 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2249 size_t m = (lo + hi) / 2;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2250 if (d[7 + 3 * m + 1] < off)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2251 lo = m + 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2252 else if (d[7 + 3 * m + 1] == off)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2253 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2254 ptrs[cnt + i] = (void *) d[7 + 3 * m];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2255 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2256 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2257 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2258 hi = m - 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2259 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2260 if (lo > hi)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2261 gomp_fatal ("couldn't find matching task_reduction or reduction "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2262 "with task modifier for %p", ptrs[i]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2263 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2264 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2265 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2266
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2267 struct gomp_taskgroup *
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2268 gomp_parallel_reduction_register (uintptr_t *data, unsigned nthreads)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2269 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2270 struct gomp_taskgroup *taskgroup = gomp_taskgroup_init (NULL);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2271 gomp_reduction_register (data, NULL, NULL, nthreads);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2272 taskgroup->reductions = data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2273 return taskgroup;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2274 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2275
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2276 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2277 gomp_workshare_task_reduction_register (uintptr_t *data, uintptr_t *orig)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2278 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2279 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2280 struct gomp_team *team = thr->ts.team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2281 struct gomp_task *task = thr->task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2282 unsigned nthreads = team->nthreads;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2283 gomp_reduction_register (data, task->taskgroup->reductions, orig, nthreads);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2284 task->taskgroup->reductions = data;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2285 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2286
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2287 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2288 gomp_workshare_taskgroup_start (void)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2289 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2290 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2291 struct gomp_team *team = thr->ts.team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2292 struct gomp_task *task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2293
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2294 if (team == NULL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2295 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2296 gomp_create_artificial_team ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2297 team = thr->ts.team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2298 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2299 task = thr->task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2300 task->taskgroup = gomp_taskgroup_init (task->taskgroup);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2301 task->taskgroup->workshare = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2302 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2303
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2304 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2305 GOMP_workshare_task_reduction_unregister (bool cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2306 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2307 struct gomp_thread *thr = gomp_thread ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2308 struct gomp_task *task = thr->task;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2309 struct gomp_team *team = thr->ts.team;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2310 uintptr_t *data = task->taskgroup->reductions;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2311 ialias_call (GOMP_taskgroup_end) ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2312 if (thr->ts.team_id == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2313 ialias_call (GOMP_taskgroup_reduction_unregister) (data);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2314 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2315 htab_free ((struct htab *) data[5]);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2316
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2317 if (!cancelled)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2318 gomp_team_barrier_wait (&team->barrier);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2319 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2320
111
kono
parents: 0
diff changeset
2321 int
kono
parents: 0
diff changeset
2322 omp_in_final (void)
kono
parents: 0
diff changeset
2323 {
kono
parents: 0
diff changeset
2324 struct gomp_thread *thr = gomp_thread ();
kono
parents: 0
diff changeset
2325 return thr->task && thr->task->final_task;
kono
parents: 0
diff changeset
2326 }
kono
parents: 0
diff changeset
2327
kono
parents: 0
diff changeset
2328 ialias (omp_in_final)