<div dir="ltr">You might find <a href="https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/556869">https://software.intel.com/en-us/forums/intel-many-integrated-core/topic/556869</a> relevant.<div><br></div><div>I consider idling in the OpenMP runtime to be a sign of a badly behaved application, not a runtime bug in need of fixing.  But in any case, OMP_WAIT_POLICY/KMP_BLOCKTIME exist to address that.</div><div><br></div><div>Best,</div><div><br></div><div>Jeff</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 21, 2017 at 1:11 PM, Adhityaa Chandrasekar via Openmp-dev <span dir="ltr"><<a href="mailto:openmp-dev@lists.llvm.org" target="_blank">openmp-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hi,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">My name is Adhityaa and I'm an undergrad student. This is my first time getting involved in OpenMP development at LLVM. I have used the library a bunch of times before, but I haven't been involved in the behind-the-scenes work before.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So I was just taking a look at <a href="https://bugs.llvm.org/show_bug.cgi?id=33543" target="_blank">https://bugs.llvm.org/show_<wbr>bug.cgi?id=33543</a> and I tried solving it (it looked like a simple, reproducible bug that looked quite important). First I ran strace on the program to see exactly what was happening - I found that the threads without any tasks were issuing a whole bunch of `sched_yield()`, making the CPU go to 100%.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Then I tried going into the code. I came up with a fairly simple patch that almost solved the issue:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div><font face="monospace, monospace">--- kmp_wait_release.h<span style="white-space:pre-wrap">    </span>(revision 313888)</font></div><div><font face="monospace, monospace">+++ kmp_wait_release.h<span style="white-space:pre-wrap">   </span>(working copy)</font></div><div><font face="monospace, monospace">@@ -188,6 +188,7 @@</font></div><div><font face="monospace, monospace">   // Main wait spin loop</font></div><div><font face="monospace, monospace">   while (flag->notdone_check()) {</font></div><div><font face="monospace, monospace">     int in_pool;</font></div><div><font face="monospace, monospace">+    int executed_tasks = 1;</font></div><div><font face="monospace, monospace">     kmp_task_team_t *task_team = NULL;</font></div><div><font face="monospace, monospace">     if (__kmp_tasking_mode != tskm_immediate_exec) {</font></div><div><font face="monospace, monospace">       task_team = this_thr->th.th_task_team;</font></div><div><font face="monospace, monospace">@@ -200,10 +201,11 @@</font></div><div><font face="monospace, monospace">          disabled (KMP_TASKING=0).  */</font></div><div><font face="monospace, monospace">       if (task_team != NULL) {</font></div><div><font face="monospace, monospace">         if (TCR_SYNC_4(task_team->tt.tt_a<wbr>ctive)) {</font></div><div><font face="monospace, monospace">-          if (KMP_TASKING_ENABLED(task_team<wbr>))</font></div><div><font face="monospace, monospace">-            flag->execute_tasks(</font></div><div><font face="monospace, monospace">+          if (KMP_TASKING_ENABLED(task_team<wbr>)) {</font></div><div><font face="monospace, monospace">+            executed_tasks = flag->execute_tasks(</font></div><div><font face="monospace, monospace">                 this_thr, th_gtid, final_spin,</font></div><div><font face="monospace, monospace">                 &tasks_completed USE_ITT_BUILD_ARG(itt_sync_obj<wbr>), 0);</font></div><div><font face="monospace, monospace">+          }</font></div><div><font face="monospace, monospace">           else</font></div><div><font face="monospace, monospace">             this_thr->th.th_reap_state = KMP_SAFE_TO_REAP;</font></div><div><font face="monospace, monospace">         } else {</font></div><div><font face="monospace, monospace">@@ -269,7 +271,7 @@</font></div><div><font face="monospace, monospace">       continue;</font></div><div><font face="monospace, monospace"> </font></div><div><font face="monospace, monospace">     // Don't suspend if there is a likelihood of new tasks being spawned.</font></div><div><font face="monospace, monospace">-    if ((task_team != NULL) && TCR_4(task_team->tt.tt_found_t<wbr>asks))</font></div><div><font face="monospace, monospace">+    if ((task_team != NULL) && TCR_4(task_team->tt.tt_found_t<wbr>asks) && executed_tasks)</font></div><div><font face="monospace, monospace">       continue;</font></div><div><font face="monospace, monospace"> </font></div><div><font face="monospace, monospace"> #if KMP_USE_MONITOR</font></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Alas, this led to a deadlock - the thread went into a futex wait and was never woke again. So I looked at how GCC did things and they issue a FUTEX_WAKE_PRIVATE for INT_MAX threads at the end of things. This should solve the problem, I think?<br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Anyway, it's pretty late here and I've been at this for over 6-7 hours at a stretch, so I'm really tired. I was just wondering if I could get some help on how to proceed from here (and whether I'm even on the right track).</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thanks,</div><div style="font-size:12.8px">Adhityaa</div></div>
<br>______________________________<wbr>_________________<br>
Openmp-dev mailing list<br>
<a href="mailto:Openmp-dev@lists.llvm.org">Openmp-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/openmp-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/openmp-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Jeff Hammond<br><a href="mailto:jeff.science@gmail.com" target="_blank">jeff.science@gmail.com</a><br><a href="http://jeffhammond.github.io/" target="_blank">http://jeffhammond.github.io/</a></div>
</div>