[llvm-branch-commits] [openmp] release/22.x: [openmp][tests] Fix bug63197.c (#183508) (PR #184086)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Mar 2 01:57:27 PST 2026


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/184086

Backport 368b884869651b69b14b836b25206aa62b501496 d44e41794540d7fa85f857228a7616ec8592a7c4

Requested by: @nikic

>From 8497e562921b69a11b4658fdf201c56b11e27610 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 25 Feb 2026 15:58:23 +0100
Subject: [PATCH 1/2] [openmp] Fix bug63197.c test with 3 cores (#183269)

This test assumes that the number of available threads is not 3,
otherwise `#pragma omp parallel` and `#pragma omp parallel
num_thread(3)` are naturally going to do the same thing.

Instead use `omp_get_max_threads() - 1` as the number of threads in the
initial `omp parallel num_thread(N)` and then check that the number of
threads does not match the value in the later `omp parallel`.

(cherry picked from commit 368b884869651b69b14b836b25206aa62b501496)
---
 openmp/runtime/test/parallel/bug63197.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/openmp/runtime/test/parallel/bug63197.c b/openmp/runtime/test/parallel/bug63197.c
index c60f400b19a8f..734f5c89c0a2d 100644
--- a/openmp/runtime/test/parallel/bug63197.c
+++ b/openmp/runtime/test/parallel/bug63197.c
@@ -4,14 +4,15 @@
 #include <stdio.h>
 
 int main(int argc, char *argv[]) {
-#pragma omp parallel num_threads(3) if (0)
+  unsigned N = omp_get_max_threads() - 1;
+#pragma omp parallel num_threads(N) if (0)
 #pragma omp single
   { printf("BBB %2d\n", omp_get_num_threads()); }
 
 #pragma omp parallel
 #pragma omp single
   {
-    if (omp_get_num_threads() != 3)
+    if (omp_get_num_threads() != N)
       printf("PASS\n");
   }
   return 0;

>From f4d6d6264b6f625d6d28ce64b0632a516fb6301c Mon Sep 17 00:00:00 2001
From: Joachim <jenke at itc.rwth-aachen.de>
Date: Thu, 26 Feb 2026 17:26:47 +0100
Subject: [PATCH 2/2] [openmp][tests] Fix bug63197.c (#183508)

#183269 tried to fix the test, but the test can still randomly fail. The
OpenMP spec does not prevent the runtime to chose a smaller team size
than returned from omp_max_threads() for the second parallel region.

Using a larger value than `omp_max_threads()` in a `num_threads` clause
is valid OpenMP code. With a correct OpenMP implementation, the
team-size of the second parallel region must still be smaller or equal
the value returned from `omp_max_threads()`.

(cherry picked from commit d44e41794540d7fa85f857228a7616ec8592a7c4)
---
 openmp/runtime/test/parallel/bug63197.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/openmp/runtime/test/parallel/bug63197.c b/openmp/runtime/test/parallel/bug63197.c
index 734f5c89c0a2d..ac4c196d53743 100644
--- a/openmp/runtime/test/parallel/bug63197.c
+++ b/openmp/runtime/test/parallel/bug63197.c
@@ -3,16 +3,22 @@
 #include <omp.h>
 #include <stdio.h>
 
+/* This code tests that state pushed for the num_threads clause does not
+   reach the next parallel region. omp_get_max_threads() + 1 can never
+   be chosen as team size for the second parallel and could only be the
+   result of some left-over state from the first parallel.
+ */
+
 int main(int argc, char *argv[]) {
-  unsigned N = omp_get_max_threads() - 1;
-#pragma omp parallel num_threads(N) if (0)
+  unsigned N = omp_get_max_threads();
+#pragma omp parallel num_threads(N + 1) if (0)
 #pragma omp single
   { printf("BBB %2d\n", omp_get_num_threads()); }
 
 #pragma omp parallel
 #pragma omp single
   {
-    if (omp_get_num_threads() != N)
+    if (omp_get_num_threads() <= N)
       printf("PASS\n");
   }
   return 0;



More information about the llvm-branch-commits mailing list