Skip to content

Commit 3e8c1e4

Browse files
fix: avoid using openmp for pyodide
1 parent 5a0bb6e commit 3e8c1e4

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,5 @@ endif
106106
# Needed by pandas.test() when it looks for the pytest ini options
107107
py.install_sources('pyproject.toml', subdir: 'pandas')
108108

109+
# Pass build flags to subdirectories
109110
subdir('pandas')

pandas/_libs/algos.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def nancorr(
398398
ssqds[j] = ssqd
399399

400400
if use_parallel:
401+
# Use parallel execution with prange (only works if OpenMP is available)
401402
for xi in prange(K, schedule="dynamic", nogil=True):
402403
for yi in range(xi + 1):
403404
covxy = 0
@@ -446,6 +447,7 @@ def nancorr(
446447
else:
447448
result[xi, yi] = result[yi, xi] = NaN
448449
else:
450+
# Use sequential execution with regular range
449451
with nogil:
450452
for xi in range(K):
451453
for yi in range(xi + 1):

pandas/_libs/meson.build

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
# Add OpenMP dependency detection at the top of the file
2-
openmp_dep = dependency('openmp', required: false)
3-
if not openmp_dep.found()
4-
cc = meson.get_compiler('c')
5-
if cc.has_argument('-fopenmp')
6-
openmp_dep = declare_dependency(
7-
compile_args: ['-fopenmp'],
8-
link_args: ['-fopenmp'],
9-
)
10-
endif
11-
endif
12-
131
_algos_take_helper = custom_target(
142
'algos_take_helper_pxi',
153
output: 'algos_take_helper.pxi',
@@ -62,6 +50,15 @@ _khash_primitive_helper_dep = declare_dependency(
6250
sources: _khash_primitive_helper,
6351
)
6452

53+
# Use the parent's WebAssembly detection and OpenMP configuration
54+
# (is_pyodide_build and openmp_dep are inherited from parent meson.build)
55+
56+
# Conditional dependencies for algos module
57+
algos_deps = [_khash_primitive_helper_dep]
58+
if openmp_dep.found() and not is_pyodide_build
59+
algos_deps += [openmp_dep]
60+
endif
61+
6562
cdata = configuration_data()
6663
if cy.version().version_compare('>=3.1.0')
6764
cdata.set('freethreading_compatible', '1')
@@ -82,7 +79,7 @@ libs_sources = {
8279
# numpy include dir is implicitly included
8380
'algos': {
8481
'sources': ['algos.pyx', _algos_common_helper, _algos_take_helper],
85-
'deps': [_khash_primitive_helper_dep, openmp_dep],
82+
'deps': algos_deps,
8683
},
8784
'arrays': {'sources': ['arrays.pyx']},
8885
'groupby': {'sources': ['groupby.pyx']},

setup.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
cmdclass = versioneer.get_cmdclass()
2929

3030

31+
# Check for WebAssembly/Emscripten build environment
32+
def is_platform_emscripten():
33+
"""Check if we're building for WebAssembly/Emscripten (Pyodide)."""
34+
return (
35+
sys.platform == "emscripten"
36+
or os.environ.get("EMSCRIPTEN", "").lower() in ("1", "true", "yes")
37+
or os.environ.get("PYODIDE", "").lower() in ("1", "true", "yes")
38+
)
39+
40+
3141
def is_platform_windows():
3242
return sys.platform in ("win32", "cygwin")
3343

@@ -439,9 +449,17 @@ def srcpath(name=None, suffix=".pyx", subdir="src"):
439449
"pyxfile": "_libs/algos",
440450
"depends": _pxi_dep["algos"],
441451
"extra_compile_args": extra_compile_args
442-
+ (["-fopenmp"] if not is_platform_windows() else ["/openmp"]),
452+
+ (
453+
(["-fopenmp"] if not is_platform_windows() else ["/openmp"])
454+
if not is_platform_emscripten()
455+
else []
456+
),
443457
"extra_link_args": extra_link_args
444-
+ (["-fopenmp"] if not is_platform_windows() else []),
458+
+ (
459+
(["-fopenmp"] if not is_platform_windows() else [])
460+
if not is_platform_emscripten()
461+
else []
462+
),
445463
},
446464
"_libs.arrays": {"pyxfile": "_libs/arrays"},
447465
"_libs.groupby": {"pyxfile": "_libs/groupby"},

0 commit comments

Comments
 (0)