@@ -438,9 +438,10 @@ static kmp_int32 __kmp_push_priority_task(kmp_int32 gtid, kmp_info_t *thread,
438438
439439  __kmp_acquire_bootstrap_lock (&thread_data->td .td_deque_lock );
440440  //  Check if deque is full
441-   if  (__kmp_enable_task_throttling && TCR_4 (thread_data->td .td_deque_ntasks ) >=
442-                                           __kmp_task_maximum_ready_per_thread) {
443-     if  (__kmp_task_is_allowed (gtid, __kmp_task_stealing_constraint, taskdata,
441+   if  (TCR_4 (thread_data->td .td_deque_ntasks ) >=
442+       TASK_DEQUE_SIZE (thread_data->td )) {
443+     if  (__kmp_enable_task_throttling &&
444+         __kmp_task_is_allowed (gtid, __kmp_task_stealing_constraint, taskdata,
444445                              thread->th .th_current_task )) {
445446      __kmp_release_bootstrap_lock (&thread_data->td .td_deque_lock );
446447      KA_TRACE (20 , (" __kmp_push_priority_task: T#%d deque is full; returning " 
@@ -541,15 +542,15 @@ static kmp_int32 __kmp_push_task(kmp_int32 gtid, kmp_task_t *task) {
541542  }
542543
543544  int  locked = 0 ;
544-   //  Check if deque is full
545+   //  Check if deque is full and needs to be expanded 
545546  int  requires_resize = TCR_4 (thread_data->td .td_deque_ntasks ) >=
546547                        TASK_DEQUE_SIZE (thread_data->td );
548+   //  Check if dequeue has too many tasks and needs throttling
547549  int  requires_throttling =
548550      __kmp_enable_task_throttling && TCR_4 (thread_data->td .td_deque_ntasks ) >=
549551                                          __kmp_task_maximum_ready_per_thread;
550-   int  thread_can_execute;
551552  if  (requires_resize || requires_throttling) {
552-     thread_can_execute =
553+     int   thread_can_execute =
553554        __kmp_task_is_allowed (gtid, __kmp_task_stealing_constraint, taskdata,
554555                              thread->th .th_current_task );
555556    if  (requires_throttling && thread_can_execute) {
@@ -577,7 +578,7 @@ static kmp_int32 __kmp_push_task(kmp_int32 gtid, kmp_task_t *task) {
577578                          TCR_4 (thread_data->td .td_deque_ntasks ) >=
578579                              __kmp_task_maximum_ready_per_thread;
579580    if  (requires_resize || requires_throttling) {
580-       thread_can_execute =
581+       int   thread_can_execute =
581582          __kmp_task_is_allowed (gtid, __kmp_task_stealing_constraint, taskdata,
582583                                thread->th .th_current_task );
583584      if  (requires_throttling && thread_can_execute) {
@@ -592,6 +593,7 @@ static kmp_int32 __kmp_push_task(kmp_int32 gtid, kmp_task_t *task) {
592593      }
593594    }
594595  }
596+ 
595597  //  Must have room since no thread can add tasks but calling thread
596598  KMP_DEBUG_ASSERT (TCR_4 (thread_data->td .td_deque_ntasks ) <
597599                   TASK_DEQUE_SIZE (thread_data->td ));
@@ -924,7 +926,10 @@ static void __kmp_free_task(kmp_int32 gtid, kmp_taskdata_t *taskdata,
924926#else  /*  ! USE_FAST_MEMORY */ 
925927  __kmp_thread_free (thread, taskdata);
926928#endif 
927-   --__kmp_n_tasks_in_flight;
929+ #if  KMP_COMPILE_GLOBAL_TASK_THROTTLING
930+   if  (__kmp_enable_task_throttling)
931+       --__kmp_n_tasks_in_flight;
932+ #endif  /*  KMP_COMPILE_GLOBAL_TASK_THROTTLING */ 
928933#if  OMPX_TASKGRAPH
929934  } else  {
930935    taskdata->td_flags .complete  = 0 ;
@@ -1475,10 +1480,15 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
14751480  if  (UNLIKELY (!TCR_4 (__kmp_init_middle)))
14761481    __kmp_middle_initialize ();
14771482
1483+ #if  KMP_COMPILE_GLOBAL_TASK_THROTTLING
14781484  //  task throttling: too many tasks co-existing, emptying queue now
14791485  if  (__kmp_enable_task_throttling)
1486+   {
14801487    while  (TCR_4 (__kmp_n_tasks_in_flight.load ()) >= __kmp_task_maximum)
14811488      __kmpc_omp_taskyield (NULL , gtid, 0 );
1489+     ++__kmp_n_tasks_in_flight;
1490+   }
1491+ #endif  /*  KMP_COMPILE_GLOBAL_TASK_THROTTLING */ 
14821492
14831493  if  (flags->hidden_helper ) {
14841494    if  (__kmp_enable_hidden_helper) {
@@ -1574,7 +1584,6 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
15741584  taskdata = (kmp_taskdata_t  *)__kmp_thread_malloc (thread, shareds_offset +
15751585                                                               sizeof_shareds);
15761586#endif  /*  USE_FAST_MEMORY */ 
1577-   ++__kmp_n_tasks_in_flight;
15781587
15791588  task = KMP_TASKDATA_TO_TASK (taskdata);
15801589
0 commit comments