[OpenMP] fix race condition in test
GitOrigin-RevId: dab5d6c2ebcc9c9deec9febfe95d32442c2ae130
diff --git a/runtime/test/tasking/omp_task_red_taskloop.c b/runtime/test/tasking/omp_task_red_taskloop.c
index a56e9ce..6683ab6 100644
--- a/runtime/test/tasking/omp_task_red_taskloop.c
+++ b/runtime/test/tasking/omp_task_red_taskloop.c
@@ -51,13 +51,18 @@
}
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 {