Skip to content

python3Packages.scikit-bio: reduce openmp threads during tests - #534961

Merged
mweinelt merged 7 commits into
NixOS:staging-nextfrom
mweinelt:scikit-bio-omp-threads
Jun 25, 2026
Merged

mweinelt merged 7 commits into
NixOS:staging-nextfrom
mweinelt:scikit-bio-omp-threads

Conversation

@mweinelt

Copy link
Copy Markdown
Member

The tests finish quickly enough (4m36s for me) with just a single OpenMP thread and this prevents it from becoming a scheduling nightmare on hydra.

Things done

The tests finish quickly enough with just a single OpenMP thread and this
prevents it from becoming a scheduling nightmare on hydra.
@vcunat

vcunat commented Jun 24, 2026 •

Copy link
Copy Markdown
Member

Maybe we should have a similar default somewhere in stdenv?

@nixpkgs-ci
nixpkgs-ci Bot requested a review from TomaSajt June 24, 2026 14:18
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 6.topic: python Python is a high-level, general-purpose programming language. labels Jun 24, 2026
@mweinelt

Copy link
Copy Markdown
Member Author

I wouldn't know where to fit it in.

@nixpkgs-ci
nixpkgs-ci Bot requested a review from GaetanLepage June 24, 2026 15:10
@GrimmTheShrimp

GrimmTheShrimp commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

The dumb thing to do would be something like:

diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index 1c5c82be25b7..5eadb8da0253 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -993,6 +993,8 @@ if ((NIX_BUILD_CORES <= 0)); then
 fi
 export NIX_BUILD_CORES
 
+OMP_NUM_THREADS = "${NIX_BUILD_CORES}"
+export OMP_NUM_THREADS
 
 # Prevent SSL libraries from using certificates in /etc/ssl, unless set explicitly.
 # Leave it in impure shells for convenience.

At the cost of forcing OMP_NUM_THREADS to be whatever build cores is, with no way to opt out of that behavior.

@mweinelt

Copy link
Copy Markdown
Member Author

Yeah, this PR is not about doing the dumb thing.

@GrimmTheShrimp

GrimmTheShrimp commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

The problem is that nix (the builder) itself sets NIX_BUILD_CORES, so referencing it in nix code somewhere in stdenv building doesn't work afaiui (https://github.com/NixOS/nix/blob/cb35ae61cf12bd156158a4bf3ab18e7d8d49c271/src/nix/nix-build/nix-build.cc#L562-L565). So any global solution will either be a setup hook being propagated around, or just setting OMP_NUM_THREADS in the same place we normalize NIX_BUILD_CORES (with maybe an optional escape hatch one can use in nix).

@mweinelt

mweinelt commented Jun 24, 2026 •

Copy link
Copy Markdown
Member Author

Picking the correct value is also not simple, because OMP threads are on top of NIX_BUILD_CORES. The preference would be for the number to be small, but that may not be a great experience with some package tests.

@GrimmTheShrimp

GrimmTheShrimp commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

grepping for OMP_NUM_THREADS reveals a few other places that do similar things. Most set either 1 (most common) or 2 threads, or picking NIX_BUILD_CORES (rarest). The exceptions seem to be pixman, numpy and scipy.

pixman limits threads to a ludicrous 184, and uses NIX_BUILD_CORES otherwise:

export OMP_NUM_THREADS=$((NIX_BUILD_CORES > 184 ? 184 : NIX_BUILD_CORES))

numpy, like pixman, uses NIX_BUILD_CORES but caps at 64.

scipy uses a quarter of the NIX_BUILD_CORES:

export OMP_NUM_THREADS=$(( $NIX_BUILD_CORES / 4 ))
if [ $OMP_NUM_THREADS -eq 0 ]; then
export OMP_NUM_THREADS=1
fi

It may be sensible to set a global default of 1 or 2, but allow overriding for things where that is known to be painfully slow.

Still, probably an off-topic discussion for the proposed changes here as a quick fix. And global fix would be an stdenv rebuild and couldn't ever work as the quick bandaid that is needed.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. and removed 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. labels Jun 24, 2026
@nixpkgs-ci
nixpkgs-ci Bot requested a review from ByteSudoer June 24, 2026 22:53
It reaps a worker and checks if it has been removed right after, but this
is apparently racy.
@nixpkgs-ci
nixpkgs-ci Bot requested a review from MrMebelMan June 25, 2026 08:47
@nixpkgs-ci
nixpkgs-ci Bot requested a review from jherland June 25, 2026 09:28
@mweinelt
mweinelt added this pull request to the merge queue Jun 25, 2026
Merged via the queue into NixOS:staging-next with commit 12c1b71 Jun 25, 2026
24 checks passed
@mweinelt
mweinelt deleted the scikit-bio-omp-threads branch June 25, 2026 09:58
@vcunat

vcunat commented Jun 25, 2026

Copy link
Copy Markdown
Member

Thanks for improving these 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants