[Openmp-commits] [openmp] r273297 - Bug fix for hang when tasks used in nested parallel

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Tue Jun 21 12:12:07 PDT 2016


Author: jlpeyton
Date: Tue Jun 21 14:12:07 2016
New Revision: 273297

URL: http://llvm.org/viewvc/llvm-project?rev=273297&view=rev
Log:
Bug fix for hang when tasks used in nested parallel

Bug fix for hang when omp task and nested parallelism used together.
Still some problem remains with task state saving/restoring, but
user's case works fine now. All tasking unit tests passed as well.

Patch by Andrey Churbanov

Differential Revision: http://reviews.llvm.org/D21558

Added:
    openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c   (with props)
Modified:
    openmp/trunk/runtime/src/kmp_runtime.c

Modified: openmp/trunk/runtime/src/kmp_runtime.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_runtime.c?rev=273297&r1=273296&r2=273297&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_runtime.c (original)
+++ openmp/trunk/runtime/src/kmp_runtime.c Tue Jun 21 14:12:07 2016
@@ -1459,8 +1459,8 @@ __kmp_fork_call(
 
     // Nested level will be an index in the nested nthreads array
     level         = parent_team->t.t_level;
-#if OMP_40_ENABLED
     active_level  = parent_team->t.t_active_level; // is used to launch non-serial teams even if nested is not allowed
+#if OMP_40_ENABLED
     teams_level    = master_th->th.th_teams_level; // needed to check nesting inside the teams
 #endif
 #if KMP_NESTED_HOT_TEAMS
@@ -2051,7 +2051,7 @@ __kmp_fork_call(
                       __kmp_gtid_from_thread( master_th ), master_th->th.th_task_team,
                       parent_team, team->t.t_task_team[master_th->th.th_task_state], team ) );
 
-        if ( level || master_th->th.th_task_team ) {
+        if ( active_level || master_th->th.th_task_team ) {
             // Take a memo of master's task_state
             KMP_DEBUG_ASSERT(master_th->th.th_task_state_memo_stack);
             if (master_th->th.th_task_state_top >= master_th->th.th_task_state_stack_sz) { // increase size
@@ -2074,7 +2074,7 @@ __kmp_fork_call(
             master_th->th.th_task_state_memo_stack[master_th->th.th_task_state_top] = master_th->th.th_task_state;
             master_th->th.th_task_state_top++;
 #if KMP_NESTED_HOT_TEAMS
-            if (team == master_th->th.th_hot_teams[level].hot_team) { // Restore master's nested state if nested hot team
+            if (team == master_th->th.th_hot_teams[active_level].hot_team) { // Restore master's nested state if nested hot team
                 master_th->th.th_task_state = master_th->th.th_task_state_memo_stack[master_th->th.th_task_state_top];
             }
             else {

Added: openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c?rev=273297&view=auto
==============================================================================
--- openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c (added)
+++ openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c Tue Jun 21 14:12:07 2016
@@ -0,0 +1,32 @@
+// RUN: %libomp-compile-and-run
+#include <stdio.h>
+#include <omp.h>
+
+/*
+ * This test would hang when level instead of active level
+ * used to push task state.
+ */
+
+int main()
+{
+  // If num_threads is changed to a value greater than 1, then the test passes
+  #pragma omp parallel num_threads(1)
+  {
+    #pragma omp parallel
+    printf("Hello World from thread %d\n", omp_get_thread_num());
+  }
+
+  printf("omp_num_threads: %d\n", omp_get_max_threads());
+
+  #pragma omp parallel
+  {
+    #pragma omp master
+    #pragma omp task default(none)
+    {
+      printf("%d is executing this task\n", omp_get_thread_num());
+    }
+  }
+
+  printf("pass\n");
+  return 0;
+}

Propchange: openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Rev URL

Propchange: openmp/trunk/runtime/test/tasking/nested_parallel_tasking.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the Openmp-commits mailing list