From d7399beaf63fe9e973bab8747aab9c4f25f6b228 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Thu, 27 Aug 2026 20:04:02 -0700 Subject: [PATCH 1/4] Add NUMBA_SMART_PRIVATIZE default to true to give old behavior of only used in region to be private. If set to false then such variables become shared. --- src/numba/openmp/config.py | 1 + src/numba/openmp/omp_lower.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/numba/openmp/config.py b/src/numba/openmp/config.py index 84e2edc48545..42b133f3eb41 100644 --- a/src/numba/openmp/config.py +++ b/src/numba/openmp/config.py @@ -25,3 +25,4 @@ def _safe_readenv(name, ctor, default): OPENMP_DISABLED = _safe_readenv("NUMBA_OPENMP_DISABLED", int, 0) # Use toolchain for device code compilation by default to avoid issues with libomptarget compatibility checks. OPENMP_DEVICE_TOOLCHAIN = _safe_readenv("NUMBA_OPENMP_DEVICE_TOOLCHAIN", int, 1) +SMART_PRIVATIZE = _safe_readenv("NUMBA_SMART_PRIVATIZE", int, 1) diff --git a/src/numba/openmp/omp_lower.py b/src/numba/openmp/omp_lower.py index 955fe81e8d7a..d54a20a1fc25 100644 --- a/src/numba/openmp/omp_lower.py +++ b/src/numba/openmp/omp_lower.py @@ -18,7 +18,7 @@ import sys import os -from .config import DEBUG_OPENMP +from .config import DEBUG_OPENMP, SMART_PRIVATIZE from .parser import openmp_parser from .analysis import ( remove_ssa, @@ -304,7 +304,10 @@ def should_be_firstprivate(var_name): # All private variables (user-defined and compiler-generated) for var_name in sorted(private_to_region): - add_clause(var_name, "QUAL.OMP.PRIVATE") + if SMART_PRIVATIZE: + add_clause(var_name, "QUAL.OMP.PRIVATE") + else: + add_clause(var_name, "QUAL.OMP.SHARED") def make_implicit_explicit_target( self, From daf397810f473712e377ee796a93c64eeb21024e Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 2 Sep 2026 12:58:23 -0700 Subject: [PATCH 2/4] Default smart privatize to off. --- src/numba/openmp/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/numba/openmp/config.py b/src/numba/openmp/config.py index 42b133f3eb41..10fc2b2357d4 100644 --- a/src/numba/openmp/config.py +++ b/src/numba/openmp/config.py @@ -25,4 +25,4 @@ def _safe_readenv(name, ctor, default): OPENMP_DISABLED = _safe_readenv("NUMBA_OPENMP_DISABLED", int, 0) # Use toolchain for device code compilation by default to avoid issues with libomptarget compatibility checks. OPENMP_DEVICE_TOOLCHAIN = _safe_readenv("NUMBA_OPENMP_DEVICE_TOOLCHAIN", int, 1) -SMART_PRIVATIZE = _safe_readenv("NUMBA_SMART_PRIVATIZE", int, 1) +SMART_PRIVATIZE = _safe_readenv("NUMBA_SMART_PRIVATIZE", int, 0) From eefad1f55e88a9ca0e092dfa1bf9bd216113d351 Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 2 Sep 2026 14:07:05 -0700 Subject: [PATCH 3/4] Mark var x as private in test_pi_loop variants. --- src/numba/openmp/tests/test_openmp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/numba/openmp/tests/test_openmp.py b/src/numba/openmp/tests/test_openmp.py index c3aee25fa37c..411ad456ee9e 100644 --- a/src/numba/openmp/tests/test_openmp.py +++ b/src/numba/openmp/tests/test_openmp.py @@ -4610,7 +4610,7 @@ def test_impl(num_steps): omp_set_num_threads(4) with openmp("parallel"): - with openmp("for reduction(+:the_sum) schedule(static)"): + with openmp("for private(x) reduction(+:the_sum) schedule(static)"): for j in range(num_steps): x = ((j - 1) - 0.5) * step the_sum += 4.0 / (1.0 + x * x) @@ -4629,7 +4629,7 @@ def test_impl(num_steps): the_sum = 0.0 omp_set_num_threads(4) - with openmp("parallel for reduction(+:the_sum) schedule(static)"): + with openmp("parallel for private(x) reduction(+:the_sum) schedule(static)"): for j in range(num_steps): x = ((j - 1) - 0.5) * step the_sum += 4.0 / (1.0 + x * x) @@ -4647,7 +4647,7 @@ def test_impl(num_steps): the_sum = 0.0 omp_set_num_threads(4) - with openmp("loop reduction(+:the_sum) schedule(static)"): + with openmp("loop private(x) reduction(+:the_sum) schedule(static)"): for j in range(num_steps): x = ((j - 1) - 0.5) * step the_sum += 4.0 / (1.0 + x * x) From a6b0a93ee4d419a3448f886393f5f4fbf57a875a Mon Sep 17 00:00:00 2001 From: "Todd A. Anderson" Date: Wed, 2 Sep 2026 14:51:31 -0700 Subject: [PATCH 4/4] Add explicit private. --- src/numba/openmp/tests/test_openmp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/numba/openmp/tests/test_openmp.py b/src/numba/openmp/tests/test_openmp.py index 411ad456ee9e..c61e815bd905 100644 --- a/src/numba/openmp/tests/test_openmp.py +++ b/src/numba/openmp/tests/test_openmp.py @@ -2050,7 +2050,7 @@ def test_impl(N, iters): with openmp("parallel"): with openmp("barrier"): pass - with openmp("for private(p, sum)"): + with openmp("for private(p, sum, i)"): for _ in range(iters): with openmp("critical"): p = count @@ -2074,7 +2074,7 @@ def test_impl(N): omp_set_num_threads(N) ca = np.zeros(N) sum = 0 - with openmp("parallel private(sum) shared(c)"): + with openmp("parallel private(sum, i) shared(c)"): c = N with openmp("barrier"): pass @@ -2117,7 +2117,7 @@ def test_impl(N): omp_set_num_threads(N) a = np.zeros((2, N)) sa = np.zeros(N) - with openmp("parallel private(a0c, sum, tn)"): + with openmp("parallel private(a0c, sum, tn, j)"): tn = omp_get_thread_num() with openmp("barrier"): pass