From 54f7a2837c04e7f660aee09adfcf0e2c74b3f7ac Mon Sep 17 00:00:00 2001
From: Thierry <thierry.gautier@inrialpes.fr>
Date: Fri, 12 Jan 2018 15:48:26 +0100
Subject: [PATCH] Return from execute task loop to improve perf

---
 runtime/src/kmp_tasking.cpp | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/runtime/src/kmp_tasking.cpp b/runtime/src/kmp_tasking.cpp
index 672f958..d5c67e7 100644
--- a/runtime/src/kmp_tasking.cpp
+++ b/runtime/src/kmp_tasking.cpp
@@ -2208,7 +2208,7 @@ static kmp_queue_data_t *__kmp_select_queue(
         CHECK_RETURN(&current_team->tt.tt_task_private_queues[KMP_LEVEL_NUMA][node]);
         CHECK_RETURN(&current_team->tt.tt_task_queues[KMP_LEVEL_CORE][cpu]); // cpu
         CHECK_RETURN(&current_team->tt.tt_task_queues[KMP_LEVEL_NUMA][node]);
-        //KMP_YIELD( __kmp_library == library_throughput );   // Yield before executing next task
+        KMP_YIELD( __kmp_library == library_throughput );   // Yield before executing next task
       }
       *islocal = 1;
       CHECK_RETURN(&current_team->tt.tt_task_queues[KMP_LEVEL_THREAD][tid]); // cpu
@@ -2669,6 +2669,7 @@ static inline int __kmp_execute_tasks_template(
             if (victim >= tid) {
               ++victim; // Adjusts random distribution to exclude self
             }
+            
             // Found a potential victim
             other_thread = threads_data[victim].td.td_thr;
             // There is a slight chance that __kmp_enable_tasking() did not wake
@@ -2847,9 +2848,8 @@ static inline int __kmp_execute_tasks_template(
 #endif
 #if LIBOMP_USE_AFFINITY || LIBOMP_USE_THEQUEUE
     //TG: avoid to return if flag condition is not check - WARN: threads are higly active
-    if (1) //(flag != NULL && flag->done_check())
+    if (flag != NULL && flag->done_check())
 #else
-    if (nthreads !=1)
 #endif
     {
       KA_TRACE(15,
@@ -2861,14 +2861,22 @@ static inline int __kmp_execute_tasks_template(
             GTID_TO_OMPT_THREAD_ID(gtid), (uint64_t)IDLE_STATE, cpu, node );
       }
 #endif
-        return FALSE;
+      return FALSE;
     }
+#if LIBOMP_USE_AFFINITY || LIBOMP_USE_THEQUEUE
+    if (final_spin)
+    {
+      return FALSE;
+   }
+#else
     else
     {
+      return FALSE;
       use_own_tasks=1;
       victim=-2;
       new_victim=0;
     }
+#endif
   }
 }
 
-- 
GitLab