Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit initial OpenBLAS thread count #46844

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions stdlib/OpenBLAS_jll/src/OpenBLAS_jll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ function __init__()
ENV["OPENBLAS_MAIN_FREE"] = "1"
end

# Ensure that OpenBLAS does not grab a huge amount of memory at first,
# since it instantly allocates scratch buffer space for the number of
# threads it thinks it needs to use.
# X-ref: https://github.com/xianyi/OpenBLAS/blob/c43ec53bdd00d9423fc609d7b7ecb35e7bf41b85/README.md#setting-the-number-of-threads-using-environment-variables
# X-ref: https://github.com/JuliaLang/julia/issues/45434
if !haskey(ENV, "OPENBLAS_NUM_THREADS") &&
!haskey(ENV, "GOTO_NUM_THREADS") &&
!haskey(ENV, "OMP_NUM_THREADS")
# We set this to `1` here, and then LinearAlgebra will update
# to the true value in its `__init__()` function.
ENV["OPENBLAS_NUM_THREADS"] = "1"
end

global libopenblas_handle = dlopen(libopenblas)
global libopenblas_path = dlpath(libopenblas_handle)
global artifact_dir = dirname(Sys.BINDIR)
Expand Down