[Openmp-commits] [openmp] r254321 - Fix crash when __kmp_task_team_setup called for single threaded team

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Mon Nov 30 12:05:14 PST 2015


Author: jlpeyton
Date: Mon Nov 30 14:05:13 2015
New Revision: 254321

URL: http://llvm.org/viewvc/llvm-project?rev=254321&view=rev
Log:
Fix crash when __kmp_task_team_setup called for single threaded team

The task_team pointer is dereferenced unconditionally which causes a SEGFAULT
when it is NULL (e.g. for serialized parallel, that can happen for "teams"
construct or for "target nowait").  The solution is to skip second task team
setup for single thread team.

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

Modified:
    openmp/trunk/runtime/src/kmp_tasking.c

Modified: openmp/trunk/runtime/src/kmp_tasking.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_tasking.c?rev=254321&r1=254320&r2=254321&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_tasking.c (original)
+++ openmp/trunk/runtime/src/kmp_tasking.c Mon Nov 30 14:05:13 2015
@@ -2537,7 +2537,6 @@ __kmp_wait_to_unref_task_teams(void)
 //------------------------------------------------------------------------------
 // __kmp_task_team_setup:  Create a task_team for the current team, but use
 // an already created, unused one if it already exists.
-// This may be called by any thread, but only for teams with # threads >1.
 void
 __kmp_task_team_setup( kmp_info_t *this_thr, kmp_team_t *team, int always )
 {
@@ -2557,28 +2556,30 @@ __kmp_task_team_setup( kmp_info_t *this_
     // previous task_team struct(above), until they receive the signal to stop checking for tasks (they can't safely
     // reference the kmp_team_t struct, which could be reallocated by the master thread). No task teams are formed for 
     // serialized teams.
-    int other_team = 1 - this_thr->th.th_task_state;
-    if (team->t.t_task_team[other_team] == NULL && team->t.t_nproc > 1) { // setup other team as well
-        team->t.t_task_team[other_team] = __kmp_allocate_task_team( this_thr, team );
-        KA_TRACE(20, ("__kmp_task_team_setup: Master T#%d created second new task_team %p for team %d at parity=%d\n",
-                      __kmp_gtid_from_thread( this_thr ), team->t.t_task_team[other_team],
-                      ((team != NULL) ? team->t.t_id : -1), other_team ));
-    }
-    else { // Leave the old task team struct in place for the upcoming region; adjust as needed
-        kmp_task_team_t *task_team = team->t.t_task_team[other_team];
-        if (!task_team->tt.tt_active || team->t.t_nproc != task_team->tt.tt_nproc) {
-            TCW_4(task_team->tt.tt_nproc, team->t.t_nproc);
-            TCW_4(task_team->tt.tt_found_tasks, FALSE);
+    if (team->t.t_nproc > 1) {
+        int other_team = 1 - this_thr->th.th_task_state;
+        if (team->t.t_task_team[other_team] == NULL) { // setup other team as well
+                team->t.t_task_team[other_team] = __kmp_allocate_task_team( this_thr, team );
+                KA_TRACE(20, ("__kmp_task_team_setup: Master T#%d created second new task_team %p for team %d at parity=%d\n",
+                                __kmp_gtid_from_thread( this_thr ), team->t.t_task_team[other_team],
+                              ((team != NULL) ? team->t.t_id : -1), other_team ));
+        }
+        else { // Leave the old task team struct in place for the upcoming region; adjust as needed
+            kmp_task_team_t *task_team = team->t.t_task_team[other_team];
+            if (!task_team->tt.tt_active || team->t.t_nproc != task_team->tt.tt_nproc) {
+                TCW_4(task_team->tt.tt_nproc, team->t.t_nproc);
+                TCW_4(task_team->tt.tt_found_tasks, FALSE);
 #if OMP_41_ENABLED
-            TCW_4(task_team->tt.tt_found_proxy_tasks, FALSE);
+                TCW_4(task_team->tt.tt_found_proxy_tasks, FALSE);
 #endif
-            TCW_4(task_team->tt.tt_unfinished_threads, team->t.t_nproc );
-            TCW_4(task_team->tt.tt_active, TRUE );
+                TCW_4(task_team->tt.tt_unfinished_threads, team->t.t_nproc );
+                TCW_4(task_team->tt.tt_active, TRUE );
+            }
+            // if team size has changed, the first thread to enable tasking will realloc threads_data if necessary
+            KA_TRACE(20, ("__kmp_task_team_setup: Master T#%d reset next task_team %p for team %d at parity=%d\n",
+                          __kmp_gtid_from_thread( this_thr ), team->t.t_task_team[other_team],
+                          ((team != NULL) ? team->t.t_id : -1), other_team ));
         }
-        // if team size has changed, the first thread to enable tasking will realloc threads_data if necessary
-        KA_TRACE(20, ("__kmp_task_team_setup: Master T#%d reset next task_team %p for team %d at parity=%d\n",
-                      __kmp_gtid_from_thread( this_thr ), team->t.t_task_team[other_team],
-                      ((team != NULL) ? team->t.t_id : -1), other_team ));
     }
 }
 




More information about the Openmp-commits mailing list