Skip to content

Commit

Permalink
Limit initial OpenBLAS thread count
Browse files Browse the repository at this point in the history
We set OpenBLAS's initial thread count to `1` to prevent runaway
allocation within OpenBLAS's initial thread startup.  LinearAlgebra will
later call `BLAS.set_num_threads()` to the actual value we require.
  • Loading branch information
staticfloat committed Sep 20, 2022
1 parent 81f6c23 commit d878265
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 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,15 @@ 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.
if !haskey(ENV, "OPENBLAS_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

0 comments on commit d878265

Please sign in to comment.