[Openmp-commits] [openmp] d67c91b - [OpenMP] Insert missing variable update inside loop

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Tue May 23 07:19:33 PDT 2023


Author: Jonathan Peyton
Date: 2023-05-23T09:19:04-05:00
New Revision: d67c91b5e728d94376873c04ffac3ba6d29b95b8

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

LOG: [OpenMP] Insert missing variable update inside loop

While loop within task priority code did not have necessary update of
variable which could lead to hangs if two threads collided when both
attempted to execute the compare_and_exchange.

Fixes: https://github.com/llvm/llvm-project/issues/62867
Differential Revision: https://reviews.llvm.org/D151138

Added: 
    openmp/runtime/test/tasking/omp_task_priority3.c

Modified: 
    openmp/runtime/src/kmp_tasking.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 5b6c9edd77dae..ee452440176bf 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -3048,6 +3048,7 @@ static kmp_task_t *__kmp_get_priority_task(kmp_int32 gtid,
     if (__kmp_atomic_compare_store(&task_team->tt.tt_num_task_pri, ntasks,
                                    ntasks - 1))
       break;
+    ntasks = task_team->tt.tt_num_task_pri;
   } while (ntasks > 0);
   if (ntasks == 0) {
     KA_TRACE(20, ("__kmp_get_priority_task(exit #2): T#%d No tasks to get\n",

diff  --git a/openmp/runtime/test/tasking/omp_task_priority3.c b/openmp/runtime/test/tasking/omp_task_priority3.c
new file mode 100644
index 0000000000000..fc540518ecd0b
--- /dev/null
+++ b/openmp/runtime/test/tasking/omp_task_priority3.c
@@ -0,0 +1,33 @@
+// RUN: %libomp-compile && env OMP_MAX_TASK_PRIORITY=42 %libomp-run
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <omp.h>
+
+int a = 0;
+
+int main(void) {
+  int i;
+  int max_task_priority = omp_get_max_task_priority();
+  if (max_task_priority != 42) {
+    fprintf(stderr,
+            "error: omp_get_max_task_priority() returned %d instead of 42\n",
+            max_task_priority);
+    exit(EXIT_FAILURE);
+  }
+
+  for (i = 0; i < 250; ++i) {
+    #pragma omp parallel
+    {
+      #pragma omp task priority(42)
+      {
+        #pragma omp atomic
+        a++;
+      }
+    }
+  }
+
+  printf("a = %d\n", a);
+
+  return EXIT_SUCCESS;
+}


        


More information about the Openmp-commits mailing list