You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: np.matmul crashes in multi-threaded settings on windows with large matrices #27989
When multiplying large matrices in a multi-threaded case (using ThreadPoolExecutor for example) the program crashes without any error. The crash does not occur if the matrix is small enough, only a single thread is used, on linux, or if OPENBLAS_NUM_THREADS is set to 1, so perhaps this is an openblas issue.
@vladoovtcharov We could consider replacing ThreadPoolExecutor with ProcessPoolExecutor. Process-based parallelism creates separate processes for each computation, which effectively avoids threading conflicts and ensures stability when working with openblas.
Would seem like a blas issue, yes. Can you please say how you installed NumPy and what blas is being used? Installing threadpoolctl and running np.show_runtime() again should print it out.
When I test with numpy 2.2.0 just the above "runtime environment" is printed.
Yeah, weird... I might suspect threadpoolctl doesn't understand the way we pull in openblas anymore, would that make sense @mattip?
Anyway, since these are the pip install, we know what is used... Ping @mreineck maybe you have some quick insight on why it might crash?
(Although, oversubscription seems probable in this context and setting at least some lower value for the number of openblas threads seems likely advisable)
Ah, thanks, good to know. We changed the library things a bit so threadpoolctl had to adapt. (I have seen this missing a few times recently, so good to know we should just ask to update.)
Good to know, I was a bit surprised at first ;-) While I was involved a bit in the multithreading support for scipy.fft, this is not based on ThreadPoolExecutor at all, so I was not sure how I could help.
This still reproduces with the current wheels (numpy 2.5.3, OpenBLAS 0.3.34.106.0), and here it happens much faster and with small operands. The trigger is a gemm in one thread running at the same time as a gemv in another thread. With two threads it crashes within about a second (0xC0000005, no traceback) or sometimes deadlocks. gemm alone or gemv alone in both threads does not fail.
I could reproduce it without NumPy against the scipy-openblas64 wheel DLL, but not against the official OpenBLAS release binaries (0.3.27 and later). So I reported it to the wheel builds: MacPython/openblas-libs#283 (C reproducer, results by version, and the build-flag differences).
Activity
isatyamks commentedon Dec 13, 2024
@vladoovtcharov We could consider replacing ThreadPoolExecutor with ProcessPoolExecutor. Process-based parallelism creates separate processes for each computation, which effectively avoids threading conflicts and ensures stability when working with openblas.
seberg commentedon Dec 13, 2024
Would seem like a blas issue, yes. Can you please say how you installed NumPy and what blas is being used? Installing
threadpoolctland runningnp.show_runtime()again should print it out.vladoovtcharov commentedon Dec 13, 2024
With numpy 2.2.0:
With numpy 1.26.4 I get the following:
I installed both version of numpy through pip no custom compilation.
seberg commentedon Dec 13, 2024
Yeah, weird... I might suspect
threadpoolctldoesn't understand the way we pull in openblas anymore, would that make sense @mattip?Anyway, since these are the
pip install, we know what is used... Ping @mreineck maybe you have some quick insight on why it might crash?(Although, oversubscription seems probable in this context and setting at least some lower value for the number of openblas threads seems likely advisable)
vladoovtcharov commentedon Dec 13, 2024
Mistake on my part, updating to the latest
threadpoolctldoes show the rest of the information, edited answer above.seberg commentedon Dec 13, 2024
Ah, thanks, good to know. We changed the library things a bit so
threadpoolctlhad to adapt. (I have seen this missing a few times recently, so good to know we should just ask to update.)seberg commentedon Dec 16, 2024
Ack, sorry, I pinged the wrong person... @martin-frbg do you immediately happen to know if this is an OpenBLAS issue?
martin-frbg commentedon Dec 16, 2024
not a known one at least, and both 0.3.23 and 0.3.28 should use the same old-and-assumed-stable multithreading code on Windows
mreineck commentedon Dec 19, 2024
Good to know, I was a bit surprised at first ;-) While I was involved a bit in the multithreading support for
scipy.fft, this is not based onThreadPoolExecutorat all, so I was not sure how I could help.yadonpapa commentedon Oct 12, 2026
This still reproduces with the current wheels (numpy 2.5.3, OpenBLAS 0.3.34.106.0), and here it happens much faster and with small operands. The trigger is a gemm in one thread running at the same time as a gemv in another thread. With two threads it crashes within about a second (0xC0000005, no traceback) or sometimes deadlocks. gemm alone or gemv alone in both threads does not fail.
I could reproduce it without NumPy against the
scipy-openblas64wheel DLL, but not against the official OpenBLAS release binaries (0.3.27 and later). So I reported it to the wheel builds: MacPython/openblas-libs#283 (C reproducer, results by version, and the build-flag differences).NumPy reproducer:
Each case was run 3 times, 30 s per run, with Python 3.12.12:
More results with numpy 2.5.3:
OPENBLAS_NUM_THREADS=1: no failure.OPENBLAS_NUM_THREADS=2: crash or hang.OPENBLAS_NUM_THREADS=4: hang in all 3 runs.Environment: Windows 11 Pro 10.0.26300; Intel Core Ultra 9 275HX (24 cores, no SMT, no AVX-512). OpenBLAS reports Haswell, 24 threads.
Workaround: set
OPENBLAS_NUM_THREADS=1before importing numpy. This is what the OpenBLAS FAQ recommends for multi-threaded applications.