[Openmp-commits] [openmp] [OpenMP] Use half of available logical processors for collapse tests (PR #88319)

Xing Xue via Openmp-commits openmp-commits at lists.llvm.org
Mon Apr 15 08:39:24 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/3] 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/3] 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

>From cf52054c839dc69ba07a89ca92fe26a126de891b Mon Sep 17 00:00:00 2001
From: Xing Xue <xingxue at outlook.com>
Date: Mon, 15 Apr 2024 11:37:13 -0400
Subject: [PATCH 3/3] Addressed comments. * add free() * make sure num_threads
 is not 0

---
 .../runtime/test/worksharing/for/collapse_test.inc   | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/openmp/runtime/test/worksharing/for/collapse_test.inc b/openmp/runtime/test/worksharing/for/collapse_test.inc
index b7906d3f2cf6ff..fbd0a7bccbbe4e 100644
--- a/openmp/runtime/test/worksharing/for/collapse_test.inc
+++ b/openmp/runtime/test/worksharing/for/collapse_test.inc
@@ -107,12 +107,19 @@ int test() {
   unsigned uselessThreadsOpenMP = 0;
   unsigned usefulThreadsOpenMP = 0;
 
-  // Use half of the available threads/logical processor.
+  // Use half of the available threads/logical processors.
   unsigned num_threads = omp_get_max_threads() / 2;
+
+  // Make sure num_threads is not 0 after the division in case
+  // omp_get_max_threads() returns 1.
+  if (num_threads == 0)
+    num_threads = 1;
+
   if (num_threads > MAX_THREADS)
     num_threads = MAX_THREADS;
 
-  unsigned *chunkSizesOpenmp = malloc(sizeof(unsigned) * num_threads);
+  unsigned *chunkSizesOpenmp =
+      (unsigned *)malloc(sizeof(unsigned) * num_threads);
   memset(chunkSizesOpenmp, 0, sizeof(unsigned) * num_threads);
 
   // count iterations and allocate space
@@ -199,5 +206,6 @@ int test() {
   // clean up space
   FreeSpace(openmpSpace);
   FreeSpace(scalarSpace);
+  free(chunkSizesOpenmp);
   return pass;
 }



More information about the Openmp-commits mailing list