[Openmp-commits] [openmp] dab5d6c - [OpenMP] fix race condition in test

via Openmp-commits openmp-commits at lists.llvm.org
Wed Feb 17 15:28:18 PST 2021


Author: AndreyChurbanov
Date: 2021-02-18T02:27:49+03:00
New Revision: dab5d6c2ebcc9c9deec9febfe95d32442c2ae130

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

LOG: [OpenMP] fix race condition in test

Added: 
    

Modified: 
    openmp/runtime/test/tasking/omp_task_red_taskloop.c

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/test/tasking/omp_task_red_taskloop.c b/openmp/runtime/test/tasking/omp_task_red_taskloop.c
index a56e9cebed96..6683ab682591 100644
--- a/openmp/runtime/test/tasking/omp_task_red_taskloop.c
+++ b/openmp/runtime/test/tasking/omp_task_red_taskloop.c
@@ -51,13 +51,18 @@ printf("th %d (gen by th %d) passed bar%d in taskloop\n", omp_get_thread_num(),
   }
   return 0;
 }
-// res = 2*((1+2)+(2+3)+(3+4)+(4+5)+1+2+3) = 60
-#define res 60
+// res = ((1+2)+(2+3)+(3+4)+(4+5)+1+2+3) = 30
+#define res 30
 int main()
 {
   r = 0;
   #pragma omp parallel num_threads(2)
-    foo();
+  { // barrier ensures threads have started before tasks creation
+    #pragma omp barrier
+    // single ensures no race condition between taskgroup reductions
+    #pragma omp single nowait
+      foo();
+  }
   if (r == res) {
     return 0;
   } else {


        


More information about the Openmp-commits mailing list