blob: abc037b5f0ca18478ffdc0b50300b13eafaa5a2c [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001/*
2 * kmp_taskdeps.cpp
Jim Cownie5e8470a2013-09-27 10:38:44 +00003 */
4
5
6//===----------------------------------------------------------------------===//
7//
8// The LLVM Compiler Infrastructure
9//
10// This file is dual licensed under the MIT and the University of Illinois Open
11// Source Licenses. See LICENSE.txt for details.
12//
13//===----------------------------------------------------------------------===//
14
15
16//#define KMP_SUPPORT_GRAPH_OUTPUT 1
17
18#include "kmp.h"
19#include "kmp_io.h"
Jim Cownie4cc4bb42014-10-07 16:25:50 +000020#include "kmp_wait_release.h"
Jim Cownie5e8470a2013-09-27 10:38:44 +000021
22#if OMP_40_ENABLED
23
24//TODO: Improve memory allocation? keep a list of pre-allocated structures? allocate in blocks? re-use list finished list entries?
25//TODO: don't use atomic ref counters for stack-allocated nodes.
26//TODO: find an alternate to atomic refs for heap-allocated nodes?
27//TODO: Finish graph output support
28//TODO: kmp_lock_t seems a tad to big (and heavy weight) for this. Check other runtime locks
29//TODO: Any ITT support needed?
30
31#ifdef KMP_SUPPORT_GRAPH_OUTPUT
32static kmp_int32 kmp_node_id_seed = 0;
33#endif
34
35static void
36__kmp_init_node ( kmp_depnode_t *node )
37{
38 node->dn.task = NULL; // set to null initially, it will point to the right task once dependences have been processed
39 node->dn.successors = NULL;
40 __kmp_init_lock(&node->dn.lock);
41 node->dn.nrefs = 1; // init creates the first reference to the node
42#ifdef KMP_SUPPORT_GRAPH_OUTPUT
43 node->dn.id = KMP_TEST_THEN_INC32(&kmp_node_id_seed);
44#endif
45}
46
47static inline kmp_depnode_t *
48__kmp_node_ref ( kmp_depnode_t *node )
49{
50 KMP_TEST_THEN_INC32(&node->dn.nrefs);
51 return node;
52}
53
54static inline void
55__kmp_node_deref ( kmp_info_t *thread, kmp_depnode_t *node )
56{
57 if (!node) return;
58
59 kmp_int32 n = KMP_TEST_THEN_DEC32(&node->dn.nrefs) - 1;
60 if ( n == 0 ) {
61 KMP_ASSERT(node->dn.nrefs == 0);
62#if USE_FAST_MEMORY
63 __kmp_fast_free(thread,node);
64#else
65 __kmp_thread_free(thread,node);
66#endif
67 }
68}
69
70#define KMP_ACQUIRE_DEPNODE(gtid,n) __kmp_acquire_lock(&(n)->dn.lock,(gtid))
71#define KMP_RELEASE_DEPNODE(gtid,n) __kmp_release_lock(&(n)->dn.lock,(gtid))
72
73static void
74__kmp_depnode_list_free ( kmp_info_t *thread, kmp_depnode_list *list );
75
76static const kmp_int32 kmp_dephash_log2 = 6;
77static const kmp_int32 kmp_dephash_size = (1 << kmp_dephash_log2);
78
79static inline kmp_int32
80__kmp_dephash_hash ( kmp_intptr_t addr )
81{
82 //TODO alternate to try: set = (((Addr64)(addrUsefulBits * 9.618)) % m_num_sets );
83 return ((addr >> kmp_dephash_log2) ^ addr) % kmp_dephash_size;
84}
85
86static kmp_dephash_t *
87__kmp_dephash_create ( kmp_info_t *thread )
88{
89 kmp_dephash_t *h;
Jim Cownie4cc4bb42014-10-07 16:25:50 +000090
Jim Cownie5e8470a2013-09-27 10:38:44 +000091 kmp_int32 size = kmp_dephash_size * sizeof(kmp_dephash_entry_t) + sizeof(kmp_dephash_t);
Jim Cownie4cc4bb42014-10-07 16:25:50 +000092
Jim Cownie5e8470a2013-09-27 10:38:44 +000093#if USE_FAST_MEMORY
94 h = (kmp_dephash_t *) __kmp_fast_allocate( thread, size );
95#else
96 h = (kmp_dephash_t *) __kmp_thread_malloc( thread, size );
97#endif
98
Jim Cownie4cc4bb42014-10-07 16:25:50 +000099#ifdef KMP_DEBUG
Jim Cownie5e8470a2013-09-27 10:38:44 +0000100 h->nelements = 0;
101#endif
102 h->buckets = (kmp_dephash_entry **)(h+1);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000103
Jim Cownie5e8470a2013-09-27 10:38:44 +0000104 for ( kmp_int32 i = 0; i < kmp_dephash_size; i++ )
105 h->buckets[i] = 0;
106
107 return h;
108}
109
110static void
111__kmp_dephash_free ( kmp_info_t *thread, kmp_dephash_t *h )
112{
113 for ( kmp_int32 i=0; i < kmp_dephash_size; i++ ) {
114 if ( h->buckets[i] ) {
115 kmp_dephash_entry_t *next;
116 for ( kmp_dephash_entry_t *entry = h->buckets[i]; entry; entry = next ) {
117 next = entry->next_in_bucket;
118 __kmp_depnode_list_free(thread,entry->last_ins);
119 __kmp_node_deref(thread,entry->last_out);
120#if USE_FAST_MEMORY
121 __kmp_fast_free(thread,entry);
122#else
123 __kmp_thread_free(thread,entry);
124#endif
125 }
126 }
127 }
128#if USE_FAST_MEMORY
129 __kmp_fast_free(thread,h);
130#else
131 __kmp_thread_free(thread,h);
132#endif
133}
134
135static kmp_dephash_entry *
136__kmp_dephash_find ( kmp_info_t *thread, kmp_dephash_t *h, kmp_intptr_t addr )
137{
138 kmp_int32 bucket = __kmp_dephash_hash(addr);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000139
Jim Cownie5e8470a2013-09-27 10:38:44 +0000140 kmp_dephash_entry_t *entry;
141 for ( entry = h->buckets[bucket]; entry; entry = entry->next_in_bucket )
142 if ( entry->addr == addr ) break;
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000143
Jim Cownie5e8470a2013-09-27 10:38:44 +0000144 if ( entry == NULL ) {
145 // create entry. This is only done by one thread so no locking required
146#if USE_FAST_MEMORY
147 entry = (kmp_dephash_entry_t *) __kmp_fast_allocate( thread, sizeof(kmp_dephash_entry_t) );
148#else
149 entry = (kmp_dephash_entry_t *) __kmp_thread_malloc( thread, sizeof(kmp_dephash_entry_t) );
150#endif
151 entry->addr = addr;
152 entry->last_out = NULL;
153 entry->last_ins = NULL;
154 entry->next_in_bucket = h->buckets[bucket];
155 h->buckets[bucket] = entry;
156#ifdef KMP_DEBUG
157 h->nelements++;
158 if ( entry->next_in_bucket ) h->nconflicts++;
159#endif
160 }
161 return entry;
162}
163
164static kmp_depnode_list_t *
165__kmp_add_node ( kmp_info_t *thread, kmp_depnode_list_t *list, kmp_depnode_t *node )
166{
167 kmp_depnode_list_t *new_head;
168
169#if USE_FAST_MEMORY
170 new_head = (kmp_depnode_list_t *) __kmp_fast_allocate(thread,sizeof(kmp_depnode_list_t));
171#else
172 new_head = (kmp_depnode_list_t *) __kmp_thread_malloc(thread,sizeof(kmp_depnode_list_t));
173#endif
174
175 new_head->node = __kmp_node_ref(node);
176 new_head->next = list;
177
178 return new_head;
179}
180
181static void
182__kmp_depnode_list_free ( kmp_info_t *thread, kmp_depnode_list *list )
183{
184 kmp_depnode_list *next;
185
186 for ( ; list ; list = next ) {
187 next = list->next;
188
189 __kmp_node_deref(thread,list->node);
190#if USE_FAST_MEMORY
191 __kmp_fast_free(thread,list);
192#else
193 __kmp_thread_free(thread,list);
194#endif
195 }
196}
197
198static inline void
199__kmp_track_dependence ( kmp_depnode_t *source, kmp_depnode_t *sink )
200{
201#ifdef KMP_SUPPORT_GRAPH_OUTPUT
202 kmp_taskdata_t * task_source = KMP_TASK_TO_TASKDATA(source->dn.task);
203 kmp_taskdata_t * task_sink = KMP_TASK_TO_TASKDATA(sink->dn.task); // this can be NULL when if(0) ...
204
205 __kmp_printf("%d(%s) -> %d(%s)\n", source->dn.id, task_source->td_ident->psource, sink->dn.id, task_sink->td_ident->psource);
206#endif
207}
208
209template< bool filter >
210static inline kmp_int32
211__kmp_process_deps ( kmp_int32 gtid, kmp_depnode_t *node, kmp_dephash_t *hash,
212 bool dep_barrier,kmp_int32 ndeps, kmp_depend_info_t *dep_list)
213{
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000214 KA_TRACE(30, ("__kmp_process_deps<%d>: T#%d processing %d depencies : dep_barrier = %d\n", filter, gtid, ndeps, dep_barrier ) );
215
Jim Cownie5e8470a2013-09-27 10:38:44 +0000216 kmp_info_t *thread = __kmp_threads[ gtid ];
217 kmp_int32 npredecessors=0;
218 for ( kmp_int32 i = 0; i < ndeps ; i++ ) {
219 const kmp_depend_info_t * dep = &dep_list[i];
220
221 KMP_DEBUG_ASSERT(dep->flags.in);
222
223 if ( filter && dep->base_addr == 0 ) continue; // skip filtered entries
224
225 kmp_dephash_entry_t *info = __kmp_dephash_find(thread,hash,dep->base_addr);
226 kmp_depnode_t *last_out = info->last_out;
227
228 if ( dep->flags.out && info->last_ins ) {
229 for ( kmp_depnode_list_t * p = info->last_ins; p; p = p->next ) {
230 kmp_depnode_t * indep = p->node;
231 if ( indep->dn.task ) {
232 KMP_ACQUIRE_DEPNODE(gtid,indep);
233 if ( indep->dn.task ) {
234 __kmp_track_dependence(indep,node);
235 indep->dn.successors = __kmp_add_node(thread, indep->dn.successors, node);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000236 KA_TRACE(40,("__kmp_process_deps<%d>: T#%d adding dependence from %p to %p",
237 filter,gtid, KMP_TASK_TO_TASKDATA(indep->dn.task), KMP_TASK_TO_TASKDATA(node->dn.task)));
Jim Cownie5e8470a2013-09-27 10:38:44 +0000238 npredecessors++;
239 }
240 KMP_RELEASE_DEPNODE(gtid,indep);
241 }
242 }
243
244 __kmp_depnode_list_free(thread,info->last_ins);
245 info->last_ins = NULL;
246
247 } else if ( last_out && last_out->dn.task ) {
248 KMP_ACQUIRE_DEPNODE(gtid,last_out);
249 if ( last_out->dn.task ) {
250 __kmp_track_dependence(last_out,node);
251 last_out->dn.successors = __kmp_add_node(thread, last_out->dn.successors, node);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000252 KA_TRACE(40,("__kmp_process_deps<%d>: T#%d adding dependence from %p to %p",
253 filter,gtid, KMP_TASK_TO_TASKDATA(last_out->dn.task), KMP_TASK_TO_TASKDATA(node->dn.task)));
254
Jim Cownie5e8470a2013-09-27 10:38:44 +0000255 npredecessors++;
256 }
257 KMP_RELEASE_DEPNODE(gtid,last_out);
258 }
259
260 if ( dep_barrier ) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000261 // if this is a sync point in the serial sequence, then the previous outputs are guaranteed to be completed after
Jim Cownie5e8470a2013-09-27 10:38:44 +0000262 // the execution of this task so the previous output nodes can be cleared.
263 __kmp_node_deref(thread,last_out);
264 info->last_out = NULL;
265 } else {
266 if ( dep->flags.out ) {
267 __kmp_node_deref(thread,last_out);
268 info->last_out = __kmp_node_ref(node);
269 } else
270 info->last_ins = __kmp_add_node(thread, info->last_ins, node);
271 }
272
273 }
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000274
275 KA_TRACE(30, ("__kmp_process_deps<%d>: T#%d found %d predecessors\n", filter, gtid, npredecessors ) );
276
Jim Cownie5e8470a2013-09-27 10:38:44 +0000277 return npredecessors;
278}
279
280#define NO_DEP_BARRIER (false)
281#define DEP_BARRIER (true)
282
283// returns true if the task has any outstanding dependence
284static bool
285__kmp_check_deps ( kmp_int32 gtid, kmp_depnode_t *node, kmp_task_t *task, kmp_dephash_t *hash, bool dep_barrier,
286 kmp_int32 ndeps, kmp_depend_info_t *dep_list,
287 kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list )
288{
289 int i;
Jonathan Peytone8104ad2015-06-08 18:56:33 +0000290 kmp_taskdata_t * taskdata;
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000291
Jonathan Peytone8104ad2015-06-08 18:56:33 +0000292 taskdata = KMP_TASK_TO_TASKDATA(task);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000293 KA_TRACE(20, ("__kmp_check_deps: T#%d checking dependencies for task %p : %d possibly aliased dependencies, %d non-aliased depedencies : dep_barrier=%d .\n", gtid, taskdata, ndeps, ndeps_noalias, dep_barrier ) );
294
Jim Cownie5e8470a2013-09-27 10:38:44 +0000295 // Filter deps in dep_list
296 // TODO: Different algorithm for large dep_list ( > 10 ? )
297 for ( i = 0; i < ndeps; i ++ ) {
298 if ( dep_list[i].base_addr != 0 )
299 for ( int j = i+1; j < ndeps; j++ )
300 if ( dep_list[i].base_addr == dep_list[j].base_addr ) {
301 dep_list[i].flags.in |= dep_list[j].flags.in;
302 dep_list[i].flags.out |= dep_list[j].flags.out;
303 dep_list[j].base_addr = 0; // Mark j element as void
304 }
305 }
306
307 // doesn't need to be atomic as no other thread is going to be accessing this node just yet
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000308 // npredecessors is set -1 to ensure that none of the releasing tasks queues this task before we have finished processing all the dependencies
309 node->dn.npredecessors = -1;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000310
311 // used to pack all npredecessors additions into a single atomic operation at the end
312 int npredecessors;
313
314 npredecessors = __kmp_process_deps<true>(gtid, node, hash, dep_barrier, ndeps, dep_list);
315 npredecessors += __kmp_process_deps<false>(gtid, node, hash, dep_barrier, ndeps_noalias, noalias_dep_list);
316
Jim Cownie5e8470a2013-09-27 10:38:44 +0000317 node->dn.task = task;
318 KMP_MB();
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000319
320 // Account for our initial fake value
321 npredecessors++;
322
323 // Update predecessors and obtain current value to check if there are still any outstandig dependences (some tasks may have finished while we processed the dependences)
324 npredecessors = KMP_TEST_THEN_ADD32(&node->dn.npredecessors, npredecessors) + npredecessors;
325
326 KA_TRACE(20, ("__kmp_check_deps: T#%d found %d predecessors for task %p \n", gtid, npredecessors, taskdata ) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000327
328 // beyond this point the task could be queued (and executed) by a releasing task...
329 return npredecessors > 0 ? true : false;
330}
331
332void
333__kmp_release_deps ( kmp_int32 gtid, kmp_taskdata_t *task )
334{
335 kmp_info_t *thread = __kmp_threads[ gtid ];
336 kmp_depnode_t *node = task->td_depnode;
337
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000338 if ( task->td_dephash ) {
339 KA_TRACE(40, ("__kmp_realease_deps: T#%d freeing dependencies hash of task %p.\n", gtid, task ) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000340 __kmp_dephash_free(thread,task->td_dephash);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000341 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000342
343 if ( !node ) return;
344
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000345 KA_TRACE(20, ("__kmp_realease_deps: T#%d notifying succesors of task %p.\n", gtid, task ) );
346
Jim Cownie5e8470a2013-09-27 10:38:44 +0000347 KMP_ACQUIRE_DEPNODE(gtid,node);
348 node->dn.task = NULL; // mark this task as finished, so no new dependencies are generated
349 KMP_RELEASE_DEPNODE(gtid,node);
350
351 kmp_depnode_list_t *next;
352 for ( kmp_depnode_list_t *p = node->dn.successors; p; p = next ) {
353 kmp_depnode_t *successor = p->node;
354 kmp_int32 npredecessors = KMP_TEST_THEN_DEC32(&successor->dn.npredecessors) - 1;
355
356 // successor task can be NULL for wait_depends or because deps are still being processed
357 if ( npredecessors == 0 ) {
358 KMP_MB();
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000359 if ( successor->dn.task ) {
360 KA_TRACE(20, ("__kmp_realease_deps: T#%d successor %p of %p scheduled for execution.\n", gtid, successor->dn.task, task ) );
361 __kmp_omp_task(gtid,successor->dn.task,false);
362 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000363 }
364
365 next = p->next;
366 __kmp_node_deref(thread,p->node);
367#if USE_FAST_MEMORY
368 __kmp_fast_free(thread,p);
369#else
370 __kmp_thread_free(thread,p);
371#endif
372 }
373
374 __kmp_node_deref(thread,node);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000375
376 KA_TRACE(20, ("__kmp_realease_deps: T#%d all successors of %p notified of completation\n", gtid, task ) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000377}
378
379/*!
380@ingroup TASKING
381@param loc_ref location of the original task directive
382@param gtid Global Thread ID of encountering thread
383@param new_task task thunk allocated by __kmp_omp_task_alloc() for the ''new task''
384@param ndeps Number of depend items with possible aliasing
385@param dep_list List of depend items with possible aliasing
386@param ndeps_noalias Number of depend items with no aliasing
387@param noalias_dep_list List of depend items with no aliasing
388
389@return Returns either TASK_CURRENT_NOT_QUEUED if the current task was not suspendend and queued, or TASK_CURRENT_QUEUED if it was suspended and queued
390
391Schedule a non-thread-switchable task with dependences for execution
392*/
393kmp_int32
394__kmpc_omp_task_with_deps( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task,
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000395 kmp_int32 ndeps, kmp_depend_info_t *dep_list,
396 kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list )
Jim Cownie5e8470a2013-09-27 10:38:44 +0000397{
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000398
399 kmp_taskdata_t * new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
400 KA_TRACE(10, ("__kmpc_omp_task_with_deps(enter): T#%d loc=%p task=%p\n",
401 gtid, loc_ref, new_taskdata ) );
402
Jim Cownie5e8470a2013-09-27 10:38:44 +0000403 kmp_info_t *thread = __kmp_threads[ gtid ];
404 kmp_taskdata_t * current_task = thread->th.th_current_task;
405
406 bool serial = current_task->td_flags.team_serial || current_task->td_flags.tasking_ser || current_task->td_flags.final;
Andrey Churbanov535b6fa2015-05-07 17:41:51 +0000407#if OMP_41_ENABLED
408 serial = serial && !(new_taskdata->td_flags.proxy == TASK_PROXY);
409#endif
Jim Cownie5e8470a2013-09-27 10:38:44 +0000410
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000411 if ( !serial && ( ndeps > 0 || ndeps_noalias > 0 )) {
Jim Cownie5e8470a2013-09-27 10:38:44 +0000412 /* if no dependencies have been tracked yet, create the dependence hash */
413 if ( current_task->td_dephash == NULL )
414 current_task->td_dephash = __kmp_dephash_create(thread);
415
416#if USE_FAST_MEMORY
417 kmp_depnode_t *node = (kmp_depnode_t *) __kmp_fast_allocate(thread,sizeof(kmp_depnode_t));
418#else
419 kmp_depnode_t *node = (kmp_depnode_t *) __kmp_thread_malloc(thread,sizeof(kmp_depnode_t));
420#endif
421
422 __kmp_init_node(node);
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000423 new_taskdata->td_depnode = node;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000424
425 if ( __kmp_check_deps( gtid, node, new_task, current_task->td_dephash, NO_DEP_BARRIER,
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000426 ndeps, dep_list, ndeps_noalias,noalias_dep_list ) ) {
427 KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d task had blocking dependencies: "
428 "loc=%p task=%p, return: TASK_CURRENT_NOT_QUEUED\n", gtid, loc_ref,
429 new_taskdata ) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000430 return TASK_CURRENT_NOT_QUEUED;
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000431 }
Andrey Churbanov535b6fa2015-05-07 17:41:51 +0000432 } else {
433#if OMP_41_ENABLED
434 kmp_task_team_t * task_team = thread->th.th_task_team;
435 if ( task_team && task_team->tt.tt_found_proxy_tasks )
436 __kmpc_omp_wait_deps ( loc_ref, gtid, ndeps, dep_list, ndeps_noalias, noalias_dep_list );
437 else
438#endif
439 KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d ignored dependencies for task (serialized)"
440 "loc=%p task=%p\n", gtid, loc_ref, new_taskdata ) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000441 }
442
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000443 KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d task had no blocking dependencies : "
444 "loc=%p task=%p, transferring to __kmpc_omp_task\n", gtid, loc_ref,
Andrey Churbanov535b6fa2015-05-07 17:41:51 +0000445 new_taskdata ) );
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000446
Jim Cownie5e8470a2013-09-27 10:38:44 +0000447 return __kmpc_omp_task(loc_ref,gtid,new_task);
448}
449
450/*!
451@ingroup TASKING
452@param loc_ref location of the original task directive
453@param gtid Global Thread ID of encountering thread
454@param ndeps Number of depend items with possible aliasing
455@param dep_list List of depend items with possible aliasing
456@param ndeps_noalias Number of depend items with no aliasing
457@param noalias_dep_list List of depend items with no aliasing
458
459Blocks the current task until all specifies dependencies have been fulfilled.
460*/
461void
462__kmpc_omp_wait_deps ( ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list,
463 kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list )
464{
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000465 KA_TRACE(10, ("__kmpc_omp_wait_deps(enter): T#%d loc=%p\n", gtid, loc_ref) );
466
467 if ( ndeps == 0 && ndeps_noalias == 0 ) {
468 KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no dependencies to wait upon : loc=%p\n", gtid, loc_ref) );
469 return;
470 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000471
472 kmp_info_t *thread = __kmp_threads[ gtid ];
473 kmp_taskdata_t * current_task = thread->th.th_current_task;
474
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000475 // We can return immediately as:
Andrey Churbanov535b6fa2015-05-07 17:41:51 +0000476 // - dependences are not computed in serial teams (except if we have proxy tasks)
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000477 // - if the dephash is not yet created it means we have nothing to wait for
Andrey Churbanov535b6fa2015-05-07 17:41:51 +0000478 bool ignore = current_task->td_flags.team_serial || current_task->td_flags.tasking_ser || current_task->td_flags.final;
479#if OMP_41_ENABLED
480 ignore = ignore && thread->th.th_task_team->tt.tt_found_proxy_tasks == FALSE;
481#endif
482 ignore = ignore || current_task->td_dephash == NULL;
483
484 if ( ignore ) {
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000485 KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no blocking dependencies : loc=%p\n", gtid, loc_ref) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000486 return;
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000487 }
Jim Cownie5e8470a2013-09-27 10:38:44 +0000488
489 kmp_depnode_t node;
490 __kmp_init_node(&node);
491
492 if (!__kmp_check_deps( gtid, &node, NULL, current_task->td_dephash, DEP_BARRIER,
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000493 ndeps, dep_list, ndeps_noalias, noalias_dep_list )) {
494 KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no blocking dependencies : loc=%p\n", gtid, loc_ref) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000495 return;
Jim Cownie5e8470a2013-09-27 10:38:44 +0000496 }
497
Jim Cownie4cc4bb42014-10-07 16:25:50 +0000498 int thread_finished = FALSE;
499 kmp_flag_32 flag((volatile kmp_uint32 *)&(node.dn.npredecessors), 0U);
500 while ( node.dn.npredecessors > 0 ) {
501 flag.execute_tasks(thread, gtid, FALSE, &thread_finished,
502#if USE_ITT_BUILD
503 NULL,
504#endif
505 __kmp_task_stealing_constraint );
506 }
507
508 KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d finished waiting : loc=%p\n", gtid, loc_ref) );
Jim Cownie5e8470a2013-09-27 10:38:44 +0000509}
510
511#endif /* OMP_40_ENABLED */
512