1 /*
2  * kmp_taskdeps.cpp
3  */
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"
20 #include "kmp_wait_release.h"
21 
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
32 static kmp_int32 kmp_node_id_seed = 0;
33 #endif
34 
35 static 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 
47 static 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 
54 static 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 
73 static void
74 __kmp_depnode_list_free ( kmp_info_t *thread, kmp_depnode_list *list );
75 
76 enum {
77     KMP_DEPHASH_OTHER_SIZE = 97,
78     KMP_DEPHASH_MASTER_SIZE = 997
79 };
80 
81 static inline kmp_int32
82 __kmp_dephash_hash ( kmp_intptr_t addr, size_t hsize )
83 {
84     //TODO alternate to try: set = (((Addr64)(addrUsefulBits * 9.618)) % m_num_sets );
85     return ((addr >> 6) ^ (addr >> 2)) % hsize;
86 }
87 
88 static kmp_dephash_t *
89 __kmp_dephash_create ( kmp_info_t *thread, kmp_taskdata_t *current_task )
90 {
91     kmp_dephash_t *h;
92 
93     size_t h_size;
94 
95     if ( current_task->td_flags.tasktype == TASK_IMPLICIT )
96         h_size = KMP_DEPHASH_MASTER_SIZE;
97     else
98         h_size = KMP_DEPHASH_OTHER_SIZE;
99 
100     kmp_int32 size = h_size * sizeof(kmp_dephash_entry_t) + sizeof(kmp_dephash_t);
101 
102 #if USE_FAST_MEMORY
103     h = (kmp_dephash_t *) __kmp_fast_allocate( thread, size );
104 #else
105     h = (kmp_dephash_t *) __kmp_thread_malloc( thread, size );
106 #endif
107     h->size = h_size;
108 
109 #ifdef KMP_DEBUG
110     h->nelements = 0;
111     h->nconflicts = 0;
112 #endif
113     h->buckets = (kmp_dephash_entry **)(h+1);
114 
115     for ( size_t i = 0; i < h_size; i++ )
116         h->buckets[i] = 0;
117 
118     return h;
119 }
120 
121 static void
122 __kmp_dephash_free ( kmp_info_t *thread, kmp_dephash_t *h )
123 {
124     for ( size_t i=0; i < h->size; i++ ) {
125         if ( h->buckets[i] ) {
126             kmp_dephash_entry_t *next;
127             for ( kmp_dephash_entry_t *entry = h->buckets[i]; entry; entry = next ) {
128                 next = entry->next_in_bucket;
129                 __kmp_depnode_list_free(thread,entry->last_ins);
130                 __kmp_node_deref(thread,entry->last_out);
131 #if USE_FAST_MEMORY
132                 __kmp_fast_free(thread,entry);
133 #else
134                 __kmp_thread_free(thread,entry);
135 #endif
136             }
137         }
138     }
139 #if USE_FAST_MEMORY
140     __kmp_fast_free(thread,h);
141 #else
142     __kmp_thread_free(thread,h);
143 #endif
144 }
145 
146 static kmp_dephash_entry *
147 __kmp_dephash_find ( kmp_info_t *thread, kmp_dephash_t *h, kmp_intptr_t addr )
148 {
149     kmp_int32 bucket = __kmp_dephash_hash(addr,h->size);
150 
151     kmp_dephash_entry_t *entry;
152     for ( entry = h->buckets[bucket]; entry; entry = entry->next_in_bucket )
153         if ( entry->addr == addr ) break;
154 
155     if ( entry == NULL ) {
156         // create entry. This is only done by one thread so no locking required
157 #if USE_FAST_MEMORY
158         entry = (kmp_dephash_entry_t *) __kmp_fast_allocate( thread, sizeof(kmp_dephash_entry_t) );
159 #else
160         entry = (kmp_dephash_entry_t *) __kmp_thread_malloc( thread, sizeof(kmp_dephash_entry_t) );
161 #endif
162         entry->addr = addr;
163         entry->last_out = NULL;
164         entry->last_ins = NULL;
165         entry->next_in_bucket = h->buckets[bucket];
166         h->buckets[bucket] = entry;
167 #ifdef KMP_DEBUG
168         h->nelements++;
169         if ( entry->next_in_bucket ) h->nconflicts++;
170 #endif
171     }
172     return entry;
173 }
174 
175 static kmp_depnode_list_t *
176 __kmp_add_node ( kmp_info_t *thread, kmp_depnode_list_t *list, kmp_depnode_t *node )
177 {
178     kmp_depnode_list_t *new_head;
179 
180 #if USE_FAST_MEMORY
181     new_head = (kmp_depnode_list_t *) __kmp_fast_allocate(thread,sizeof(kmp_depnode_list_t));
182 #else
183     new_head = (kmp_depnode_list_t *) __kmp_thread_malloc(thread,sizeof(kmp_depnode_list_t));
184 #endif
185 
186     new_head->node = __kmp_node_ref(node);
187     new_head->next = list;
188 
189     return new_head;
190 }
191 
192 static void
193 __kmp_depnode_list_free ( kmp_info_t *thread, kmp_depnode_list *list )
194 {
195     kmp_depnode_list *next;
196 
197     for ( ; list ; list = next ) {
198         next = list->next;
199 
200         __kmp_node_deref(thread,list->node);
201 #if USE_FAST_MEMORY
202         __kmp_fast_free(thread,list);
203 #else
204         __kmp_thread_free(thread,list);
205 #endif
206     }
207 }
208 
209 static inline void
210 __kmp_track_dependence ( kmp_depnode_t *source, kmp_depnode_t *sink,
211                          kmp_task_t *sink_task )
212 {
213 #ifdef KMP_SUPPORT_GRAPH_OUTPUT
214     kmp_taskdata_t * task_source = KMP_TASK_TO_TASKDATA(source->dn.task);
215     // do not use sink->dn.task as that is only filled after the dependencies
216     // are already processed!
217     kmp_taskdata_t * task_sink = KMP_TASK_TO_TASKDATA(sink_task);
218 
219     __kmp_printf("%d(%s) -> %d(%s)\n", source->dn.id, task_source->td_ident->psource, sink->dn.id, task_sink->td_ident->psource);
220 #endif
221 #if OMPT_SUPPORT && OMPT_TRACE
222     /* OMPT tracks dependences between task (a=source, b=sink) in which
223        task a blocks the execution of b through the ompt_new_dependence_callback */
224     if (ompt_enabled &&
225         ompt_callbacks.ompt_callback(ompt_event_task_dependence_pair))
226     {
227         kmp_taskdata_t * task_source = KMP_TASK_TO_TASKDATA(source->dn.task);
228         kmp_taskdata_t * task_sink = KMP_TASK_TO_TASKDATA(sink_task);
229 
230         ompt_callbacks.ompt_callback(ompt_event_task_dependence_pair)(
231           task_source->ompt_task_info.task_id,
232           task_sink->ompt_task_info.task_id);
233     }
234 #endif /* OMPT_SUPPORT && OMPT_TRACE */
235 }
236 
237 template< bool filter >
238 static inline kmp_int32
239 __kmp_process_deps ( kmp_int32 gtid, kmp_depnode_t *node, kmp_dephash_t *hash,
240                      bool dep_barrier,kmp_int32 ndeps, kmp_depend_info_t *dep_list,
241                      kmp_task_t *task )
242 {
243     KA_TRACE(30, ("__kmp_process_deps<%d>: T#%d processing %d depencies : dep_barrier = %d\n", filter, gtid, ndeps, dep_barrier ) );
244 
245     kmp_info_t *thread = __kmp_threads[ gtid ];
246     kmp_int32 npredecessors=0;
247     for ( kmp_int32 i = 0; i < ndeps ; i++ ) {
248         const kmp_depend_info_t * dep = &dep_list[i];
249 
250         KMP_DEBUG_ASSERT(dep->flags.in);
251 
252         if ( filter && dep->base_addr == 0 ) continue; // skip filtered entries
253 
254         kmp_dephash_entry_t *info = __kmp_dephash_find(thread,hash,dep->base_addr);
255         kmp_depnode_t *last_out = info->last_out;
256 
257         if ( dep->flags.out && info->last_ins ) {
258             for ( kmp_depnode_list_t * p = info->last_ins; p; p = p->next ) {
259                 kmp_depnode_t * indep = p->node;
260                 if ( indep->dn.task ) {
261                     KMP_ACQUIRE_DEPNODE(gtid,indep);
262                     if ( indep->dn.task ) {
263                         __kmp_track_dependence(indep,node,task);
264                         indep->dn.successors = __kmp_add_node(thread, indep->dn.successors, node);
265                         KA_TRACE(40,("__kmp_process_deps<%d>: T#%d adding dependence from %p to %p\n",
266                                  filter,gtid, KMP_TASK_TO_TASKDATA(indep->dn.task), KMP_TASK_TO_TASKDATA(task)));
267                         npredecessors++;
268                     }
269                     KMP_RELEASE_DEPNODE(gtid,indep);
270                 }
271             }
272 
273             __kmp_depnode_list_free(thread,info->last_ins);
274             info->last_ins = NULL;
275 
276         } else if ( last_out && last_out->dn.task ) {
277             KMP_ACQUIRE_DEPNODE(gtid,last_out);
278             if ( last_out->dn.task ) {
279                 __kmp_track_dependence(last_out,node,task);
280                 last_out->dn.successors = __kmp_add_node(thread, last_out->dn.successors, node);
281                 KA_TRACE(40,("__kmp_process_deps<%d>: T#%d adding dependence from %p to %p\n",
282                              filter,gtid, KMP_TASK_TO_TASKDATA(last_out->dn.task), KMP_TASK_TO_TASKDATA(task)));
283 
284                 npredecessors++;
285             }
286             KMP_RELEASE_DEPNODE(gtid,last_out);
287         }
288 
289         if ( dep_barrier ) {
290             // if this is a sync point in the serial sequence, then the previous outputs are guaranteed to be completed after
291             // the execution of this task so the previous output nodes can be cleared.
292             __kmp_node_deref(thread,last_out);
293             info->last_out = NULL;
294         } else {
295             if ( dep->flags.out ) {
296                 __kmp_node_deref(thread,last_out);
297                 info->last_out = __kmp_node_ref(node);
298             } else
299                 info->last_ins = __kmp_add_node(thread, info->last_ins, node);
300         }
301 
302     }
303 
304     KA_TRACE(30, ("__kmp_process_deps<%d>: T#%d found %d predecessors\n", filter, gtid, npredecessors ) );
305 
306     return npredecessors;
307 }
308 
309 #define NO_DEP_BARRIER (false)
310 #define DEP_BARRIER (true)
311 
312 // returns true if the task has any outstanding dependence
313 static bool
314 __kmp_check_deps ( kmp_int32 gtid, kmp_depnode_t *node, kmp_task_t *task, kmp_dephash_t *hash, bool dep_barrier,
315                    kmp_int32 ndeps, kmp_depend_info_t *dep_list,
316                    kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list )
317 {
318     int i;
319 
320 #if KMP_DEBUG
321     kmp_taskdata_t * taskdata = KMP_TASK_TO_TASKDATA(task);
322 #endif
323     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 ) );
324 
325     // Filter deps in dep_list
326     // TODO: Different algorithm for large dep_list ( > 10 ? )
327     for ( i = 0; i < ndeps; i ++ ) {
328         if ( dep_list[i].base_addr != 0 )
329             for ( int j = i+1; j < ndeps; j++ )
330                 if ( dep_list[i].base_addr == dep_list[j].base_addr ) {
331                     dep_list[i].flags.in |= dep_list[j].flags.in;
332                     dep_list[i].flags.out |= dep_list[j].flags.out;
333                     dep_list[j].base_addr = 0; // Mark j element as void
334                 }
335     }
336 
337     // doesn't need to be atomic as no other thread is going to be accessing this node just yet
338     // npredecessors is set -1 to ensure that none of the releasing tasks queues this task before we have finished processing all the dependencies
339     node->dn.npredecessors = -1;
340 
341     // used to pack all npredecessors additions into a single atomic operation at the end
342     int npredecessors;
343 
344     npredecessors = __kmp_process_deps<true>(gtid, node, hash, dep_barrier,
345       ndeps, dep_list, task);
346     npredecessors += __kmp_process_deps<false>(gtid, node, hash, dep_barrier,
347       ndeps_noalias, noalias_dep_list, task);
348 
349     node->dn.task = task;
350     KMP_MB();
351 
352     // Account for our initial fake value
353     npredecessors++;
354 
355     // 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)
356     npredecessors = KMP_TEST_THEN_ADD32(&node->dn.npredecessors, npredecessors) + npredecessors;
357 
358     KA_TRACE(20, ("__kmp_check_deps: T#%d found %d predecessors for task %p \n", gtid, npredecessors, taskdata ) );
359 
360     // beyond this point the task could be queued (and executed) by a releasing task...
361     return npredecessors > 0 ? true : false;
362 }
363 
364 void
365 __kmp_release_deps ( kmp_int32 gtid, kmp_taskdata_t *task )
366 {
367     kmp_info_t *thread = __kmp_threads[ gtid ];
368     kmp_depnode_t *node = task->td_depnode;
369 
370     if ( task->td_dephash ) {
371         KA_TRACE(40, ("__kmp_realease_deps: T#%d freeing dependencies hash of task %p.\n", gtid, task ) );
372         __kmp_dephash_free(thread,task->td_dephash);
373     }
374 
375     if ( !node ) return;
376 
377     KA_TRACE(20, ("__kmp_realease_deps: T#%d notifying succesors of task %p.\n", gtid, task ) );
378 
379     KMP_ACQUIRE_DEPNODE(gtid,node);
380     node->dn.task = NULL; // mark this task as finished, so no new dependencies are generated
381     KMP_RELEASE_DEPNODE(gtid,node);
382 
383     kmp_depnode_list_t *next;
384     for ( kmp_depnode_list_t *p = node->dn.successors; p; p = next ) {
385         kmp_depnode_t *successor = p->node;
386         kmp_int32 npredecessors = KMP_TEST_THEN_DEC32(&successor->dn.npredecessors) - 1;
387 
388         // successor task can be NULL for wait_depends or because deps are still being processed
389         if ( npredecessors == 0 ) {
390             KMP_MB();
391             if ( successor->dn.task ) {
392                 KA_TRACE(20, ("__kmp_realease_deps: T#%d successor %p of %p scheduled for execution.\n", gtid, successor->dn.task, task ) );
393                 __kmp_omp_task(gtid,successor->dn.task,false);
394             }
395         }
396 
397         next = p->next;
398         __kmp_node_deref(thread,p->node);
399 #if USE_FAST_MEMORY
400         __kmp_fast_free(thread,p);
401 #else
402         __kmp_thread_free(thread,p);
403 #endif
404     }
405 
406     __kmp_node_deref(thread,node);
407 
408     KA_TRACE(20, ("__kmp_realease_deps: T#%d all successors of %p notified of completation\n", gtid, task ) );
409 }
410 
411 /*!
412 @ingroup TASKING
413 @param loc_ref location of the original task directive
414 @param gtid Global Thread ID of encountering thread
415 @param new_task task thunk allocated by __kmp_omp_task_alloc() for the ''new task''
416 @param ndeps Number of depend items with possible aliasing
417 @param dep_list List of depend items with possible aliasing
418 @param ndeps_noalias Number of depend items with no aliasing
419 @param noalias_dep_list List of depend items with no aliasing
420 
421 @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
422 
423 Schedule a non-thread-switchable task with dependences for execution
424 */
425 kmp_int32
426 __kmpc_omp_task_with_deps( ident_t *loc_ref, kmp_int32 gtid, kmp_task_t * new_task,
427                             kmp_int32 ndeps, kmp_depend_info_t *dep_list,
428                             kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list )
429 {
430 
431     kmp_taskdata_t * new_taskdata = KMP_TASK_TO_TASKDATA(new_task);
432     KA_TRACE(10, ("__kmpc_omp_task_with_deps(enter): T#%d loc=%p task=%p\n",
433                   gtid, loc_ref, new_taskdata ) );
434 
435     kmp_info_t *thread = __kmp_threads[ gtid ];
436     kmp_taskdata_t * current_task = thread->th.th_current_task;
437 
438 #if OMPT_SUPPORT && OMPT_TRACE
439     /* OMPT grab all dependences if requested by the tool */
440     if (ompt_enabled && ndeps+ndeps_noalias > 0 &&
441         ompt_callbacks.ompt_callback(ompt_event_task_dependences))
442 	{
443         kmp_int32 i;
444 
445         new_taskdata->ompt_task_info.ndeps = ndeps+ndeps_noalias;
446         new_taskdata->ompt_task_info.deps = (ompt_task_dependence_t *)
447           KMP_OMPT_DEPS_ALLOC(thread,
448              (ndeps+ndeps_noalias)*sizeof(ompt_task_dependence_t));
449 
450         KMP_ASSERT(new_taskdata->ompt_task_info.deps != NULL);
451 
452         for (i = 0; i < ndeps; i++)
453         {
454             new_taskdata->ompt_task_info.deps[i].variable_addr =
455               (void*) dep_list[i].base_addr;
456             if (dep_list[i].flags.in && dep_list[i].flags.out)
457                 new_taskdata->ompt_task_info.deps[i].dependence_flags =
458                   ompt_task_dependence_type_inout;
459             else if (dep_list[i].flags.out)
460                 new_taskdata->ompt_task_info.deps[i].dependence_flags =
461                   ompt_task_dependence_type_out;
462             else if (dep_list[i].flags.in)
463                 new_taskdata->ompt_task_info.deps[i].dependence_flags =
464                   ompt_task_dependence_type_in;
465         }
466         for (i = 0; i < ndeps_noalias; i++)
467         {
468             new_taskdata->ompt_task_info.deps[ndeps+i].variable_addr =
469               (void*) noalias_dep_list[i].base_addr;
470             if (noalias_dep_list[i].flags.in && noalias_dep_list[i].flags.out)
471                 new_taskdata->ompt_task_info.deps[ndeps+i].dependence_flags =
472                   ompt_task_dependence_type_inout;
473             else if (noalias_dep_list[i].flags.out)
474                 new_taskdata->ompt_task_info.deps[ndeps+i].dependence_flags =
475                   ompt_task_dependence_type_out;
476             else if (noalias_dep_list[i].flags.in)
477                 new_taskdata->ompt_task_info.deps[ndeps+i].dependence_flags =
478                   ompt_task_dependence_type_in;
479         }
480     }
481 #endif /* OMPT_SUPPORT && OMPT_TRACE */
482 
483     bool serial = current_task->td_flags.team_serial || current_task->td_flags.tasking_ser || current_task->td_flags.final;
484 #if OMP_45_ENABLED
485     kmp_task_team_t * task_team = thread->th.th_task_team;
486     serial = serial && !(task_team && task_team->tt.tt_found_proxy_tasks);
487 #endif
488 
489     if ( !serial && ( ndeps > 0 || ndeps_noalias > 0 )) {
490         /* if no dependencies have been tracked yet, create the dependence hash */
491         if ( current_task->td_dephash == NULL )
492             current_task->td_dephash = __kmp_dephash_create(thread, current_task);
493 
494 #if USE_FAST_MEMORY
495         kmp_depnode_t *node = (kmp_depnode_t *) __kmp_fast_allocate(thread,sizeof(kmp_depnode_t));
496 #else
497         kmp_depnode_t *node = (kmp_depnode_t *) __kmp_thread_malloc(thread,sizeof(kmp_depnode_t));
498 #endif
499 
500         __kmp_init_node(node);
501         new_taskdata->td_depnode = node;
502 
503         if ( __kmp_check_deps( gtid, node, new_task, current_task->td_dephash, NO_DEP_BARRIER,
504                                ndeps, dep_list, ndeps_noalias,noalias_dep_list ) ) {
505             KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d task had blocking dependencies: "
506                   "loc=%p task=%p, return: TASK_CURRENT_NOT_QUEUED\n", gtid, loc_ref,
507                   new_taskdata ) );
508             return TASK_CURRENT_NOT_QUEUED;
509         }
510     } else {
511         KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d ignored dependencies for task (serialized)"
512                       "loc=%p task=%p\n", gtid, loc_ref, new_taskdata ) );
513     }
514 
515     KA_TRACE(10, ("__kmpc_omp_task_with_deps(exit): T#%d task had no blocking dependencies : "
516                   "loc=%p task=%p, transferring to __kmpc_omp_task\n", gtid, loc_ref,
517                   new_taskdata ) );
518 
519     return __kmpc_omp_task(loc_ref,gtid,new_task);
520 }
521 
522 /*!
523 @ingroup TASKING
524 @param loc_ref location of the original task directive
525 @param gtid Global Thread ID of encountering thread
526 @param ndeps Number of depend items with possible aliasing
527 @param dep_list List of depend items with possible aliasing
528 @param ndeps_noalias Number of depend items with no aliasing
529 @param noalias_dep_list List of depend items with no aliasing
530 
531 Blocks the current task until all specifies dependencies have been fulfilled.
532 */
533 void
534 __kmpc_omp_wait_deps ( ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps, kmp_depend_info_t *dep_list,
535                        kmp_int32 ndeps_noalias, kmp_depend_info_t *noalias_dep_list )
536 {
537     KA_TRACE(10, ("__kmpc_omp_wait_deps(enter): T#%d loc=%p\n", gtid, loc_ref) );
538 
539     if ( ndeps == 0 && ndeps_noalias == 0 ) {
540         KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no dependencies to wait upon : loc=%p\n", gtid, loc_ref) );
541         return;
542     }
543 
544     kmp_info_t *thread = __kmp_threads[ gtid ];
545     kmp_taskdata_t * current_task = thread->th.th_current_task;
546 
547     // We can return immediately as:
548     //   - dependences are not computed in serial teams (except if we have proxy tasks)
549     //   - if the dephash is not yet created it means we have nothing to wait for
550     bool ignore = current_task->td_flags.team_serial || current_task->td_flags.tasking_ser || current_task->td_flags.final;
551 #if OMP_45_ENABLED
552     ignore = ignore && thread->th.th_task_team != NULL && thread->th.th_task_team->tt.tt_found_proxy_tasks == FALSE;
553 #endif
554     ignore = ignore || current_task->td_dephash == NULL;
555 
556     if ( ignore ) {
557         KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no blocking dependencies : loc=%p\n", gtid, loc_ref) );
558         return;
559     }
560 
561     kmp_depnode_t node;
562     __kmp_init_node(&node);
563 
564     if (!__kmp_check_deps( gtid, &node, NULL, current_task->td_dephash, DEP_BARRIER,
565                            ndeps, dep_list, ndeps_noalias, noalias_dep_list )) {
566         KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d has no blocking dependencies : loc=%p\n", gtid, loc_ref) );
567         return;
568     }
569 
570     int thread_finished = FALSE;
571     kmp_flag_32 flag((volatile kmp_uint32 *)&(node.dn.npredecessors), 0U);
572     while ( node.dn.npredecessors > 0 ) {
573         flag.execute_tasks(thread, gtid, FALSE, &thread_finished,
574 #if USE_ITT_BUILD
575                            NULL,
576 #endif
577                            __kmp_task_stealing_constraint );
578     }
579 
580     KA_TRACE(10, ("__kmpc_omp_wait_deps(exit): T#%d finished waiting : loc=%p\n", gtid, loc_ref) );
581 }
582 
583 #endif /* OMP_40_ENABLED */
584 
585