[Openmp-commits] [openmp] [OpenMP][AIX] lower max threads to reduce collapse testing time (PR #88319)

Xing Xue via Openmp-commits openmp-commits at lists.llvm.org
Thu Apr 11 10:06:21 PDT 2024


https://github.com/xingxue-ibm updated https://github.com/llvm/llvm-project/pull/88319

>From 6b3ff06e1597c661219f13641290f346064269b5 Mon Sep 17 00:00:00 2001
From: Xing Xue <xingxue at outlook.com>
Date: Wed, 10 Apr 2024 16:38:10 -0400
Subject: [PATCH 1/2] Use lower max threads to reduce the testing time.

---
 openmp/runtime/test/worksharing/for/collapse_test.inc | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/openmp/runtime/test/worksharing/for/collapse_test.inc b/openmp/runtime/test/worksharing/for/collapse_test.inc
index de0e7e4e57f30d..37d80a56a68db1 100644
--- a/openmp/runtime/test/worksharing/for/collapse_test.inc
+++ b/openmp/runtime/test/worksharing/for/collapse_test.inc
@@ -15,7 +15,12 @@
 #define LOOP_TYPE2 LOOP_TYPES
 #define LOOP_STYPE2 LOOP_TYPES
 
+#if defined _AIX
+// Use lower max threads to reduce the testing time
+#define MAX_THREADS 64
+#else
 #define MAX_THREADS 256
+#endif
 
 #if defined VERBOSE
 #define PRINTF printf

>From d482799e3912af4958cc4679c69f9115ec2b1376 Mon Sep 17 00:00:00 2001
From: Xing Xue <xingxue at outlook.com>
Date: Thu, 11 Apr 2024 13:04:25 -0400
Subject: [PATCH 2/2] Addressed comments. * Use half of available
 threads/logical processors to avoid over-subscribing * Fix the PRINTF macro
 to get rid of warnings

---
 .../test/worksharing/for/collapse_test.inc    | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/openmp/runtime/test/worksharing/for/collapse_test.inc b/openmp/runtime/test/worksharing/for/collapse_test.inc
index 37d80a56a68db1..b7906d3f2cf6ff 100644
--- a/openmp/runtime/test/worksharing/for/collapse_test.inc
+++ b/openmp/runtime/test/worksharing/for/collapse_test.inc
@@ -15,17 +15,12 @@
 #define LOOP_TYPE2 LOOP_TYPES
 #define LOOP_STYPE2 LOOP_TYPES
 
-#if defined _AIX
-// Use lower max threads to reduce the testing time
-#define MAX_THREADS 64
-#else
 #define MAX_THREADS 256
-#endif
 
 #if defined VERBOSE
-#define PRINTF printf
+#define PRINTF(...) printf(__VA_ARGS__)
 #else
-#define PRINTF
+#define PRINTF(...)
 #endif
 
 LOOP_TYPE0 iLB, iUB;
@@ -111,12 +106,14 @@ int test() {
   unsigned scalarCount = 0;
   unsigned uselessThreadsOpenMP = 0;
   unsigned usefulThreadsOpenMP = 0;
-  unsigned chunkSizesOpenmp[MAX_THREADS] = {0};
 
-  unsigned num_threads = omp_get_max_threads();
+  // Use half of the available threads/logical processor.
+  unsigned num_threads = omp_get_max_threads() / 2;
   if (num_threads > MAX_THREADS)
     num_threads = MAX_THREADS;
-  omp_set_num_threads(num_threads);
+
+  unsigned *chunkSizesOpenmp = malloc(sizeof(unsigned) * num_threads);
+  memset(chunkSizesOpenmp, 0, sizeof(unsigned) * num_threads);
 
   // count iterations and allocate space
   LOOP { ++trueCount; }
@@ -134,10 +131,10 @@ int test() {
   // perform and record OpenMP iterations and thread use
 #pragma omp parallel num_threads(num_threads)
   {
+    unsigned gtid = omp_get_thread_num();
 #pragma omp for collapse(3) private(i, j, k)
     LOOP {
       unsigned count;
-      unsigned gtid = omp_get_thread_num();
 #pragma omp atomic update
       ++chunkSizesOpenmp[gtid];
 #pragma omp atomic capture



More information about the Openmp-commits mailing list