Skip to content

Commit d878265

Browse files
committed
Limit initial OpenBLAS thread count
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.
1 parent 81f6c23 commit d878265

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

stdlib/OpenBLAS_jll/src/OpenBLAS_jll.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ function __init__()
3737
ENV["OPENBLAS_MAIN_FREE"] = "1"
3838
end
3939

40+
# Ensure that OpenBLAS does not grab a huge amount of memory at first,
41+
# since it instantly allocates scratch buffer space for the number of
42+
# threads it thinks it needs to use.
43+
if !haskey(ENV, "OPENBLAS_NUM_THREADS")
44+
# We set this to `1` here, and then LinearAlgebra will update
45+
# to the true value in its `__init__()` function.
46+
ENV["OPENBLAS_NUM_THREADS"] = "1"
47+
end
48+
4049
global libopenblas_handle = dlopen(libopenblas)
4150
global libopenblas_path = dlpath(libopenblas_handle)
4251
global artifact_dir = dirname(Sys.BINDIR)

0 commit comments

Comments
 (0)