[Openmp-commits] [openmp] c2019c4 - [OpenMP] [test] Fix target_thread_limit.cpp to not assume 4 or more cores

Martin Storsjö via Openmp-commits openmp-commits at lists.llvm.org
Fri Sep 1 11:17:24 PDT 2023


Author: Martin Storsjö
Date: 2023-09-01T21:16:58+03:00
New Revision: c2019c416c8d7ec50aec6ac6b82c9aa4e99b0f6f

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

LOG: [OpenMP] [test] Fix target_thread_limit.cpp to not assume 4 or more cores

Previously, the test ran a section with

    #pragma omp target thread_limit(4)

and expected it to execute exactly 4 times, even though it would
in practice execute min(cores, 4) times.

Increment a counter and check that it executed 1-4 times.

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

Added: 
    

Modified: 
    openmp/runtime/test/target/target_thread_limit.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/test/target/target_thread_limit.cpp b/openmp/runtime/test/target/target_thread_limit.cpp
index 0cc3307977e974f..5e02bdb1a55c361 100644
--- a/openmp/runtime/test/target/target_thread_limit.cpp
+++ b/openmp/runtime/test/target/target_thread_limit.cpp
@@ -18,15 +18,13 @@ int main(void) {
 #pragma omp target thread_limit(tl)
   {
     printf("\ntarget: thread_limit = %d", omp_get_thread_limit());
+    int count = 0;
 // OMP51: target: thread_limit = 4
 // check whether thread_limit is honoured
-#pragma omp parallel
-    { printf("\ntarget: parallel"); }
-// OMP51: target: parallel
-// OMP51: target: parallel
-// OMP51: target: parallel
-// OMP51: target: parallel
-// OMP51-NOT: target: parallel
+#pragma omp parallel reduction(+:count)
+    { count++; }
+    printf("\ntarget: parallel: count = %d", count);
+// OMP51: target: parallel: count = {{(1|2|3|4)$}}
 
 // check whether num_threads is honoured
 #pragma omp parallel num_threads(2)
@@ -70,13 +68,12 @@ int main(void) {
 #pragma omp target thread_limit(3)
   {
     printf("\nsecond target: thread_limit = %d", omp_get_thread_limit());
+    int count = 0;
 // OMP51: second target: thread_limit = 3
-#pragma omp parallel
-    { printf("\nsecond target: parallel"); }
-    // OMP51: second target: parallel
-    // OMP51: second target: parallel
-    // OMP51: second target: parallel
-    // OMP51-NOT: second target: parallel
+#pragma omp parallel reduction(+:count)
+    { count++; }
+    printf("\nsecond target: parallel: count = %d", count);
+    // OMP51: second target: parallel: count = {{(1|2|3)$}}
   }
 
   // confirm that thread_limit's effects are limited to target region


        


More information about the Openmp-commits mailing list