[Openmp-commits] [openmp] a4f246a - [OpenMP] Fix inconsistent task state if hot team is not used

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 18 15:22:02 PST 2023


Author: Shilei Tian
Date: 2023-01-18T18:21:57-05:00
New Revision: a4f246a83e3df5f2b6c147b5bd69821d6fd17a37

URL: https://github.com/llvm/llvm-project/commit/a4f246a83e3df5f2b6c147b5bd69821d6fd17a37
DIFF: https://github.com/llvm/llvm-project/commit/a4f246a83e3df5f2b6c147b5bd69821d6fd17a37.diff

LOG: [OpenMP] Fix inconsistent task state if hot team is not used

This patch fixes the inconsistent task state when hot team is not used.
When the primary thread executes `__kmp_join_call`, it calls `__kmp_free_team`,
where worker threads will get destroyed if not using hot team. The destroy of
worker threads also reset their task state. However, the primary thread's is not
reset. When the next parallel region is encountered, in `__kmp_task_team_sync`,
the task state of thread will be flipped. Since the state of primary thread is not
reset, it is still 1, but all the worker threads will be 0, this leads to the
inconsistent task state, causing those threads are using completely different
task team.

Fix #59190.

Reviewed By: tlwilmar

Differential Revision: https://reviews.llvm.org/D141979

Added: 
    

Modified: 
    openmp/runtime/src/kmp_runtime.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index 6022dcad99acd..be0f15fff4355 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -2673,6 +2673,12 @@ void __kmp_join_call(ident_t *loc, int gtid
       master_th->th.th_task_state =
           master_th->th
               .th_task_state_memo_stack[master_th->th.th_task_state_top];
+    } else if (team != root->r.r_hot_team) {
+      // Reset the task state of primary thread if we are not hot team because
+      // in this case all the worker threads will be free, and their task state
+      // will be reset. If not reset the primary's, the task state will be
+      // inconsistent.
+      master_th->th.th_task_state = 0;
     }
     // Copy the task team from the parent team to the primary thread
     master_th->th.th_task_team =


        


More information about the Openmp-commits mailing list