Last Updated on September 29, 2023
You can check which BLAS library is used by NumPy by calling numpy.show_config().
In this tutorial, you will discover how to check which BLAS library numpy is used on your system.
Let’s get started.
Need to Know Which BLAS Library NumPy is Using
NumPy is an array library in Python.
It makes use of third-party libraries to perform array functions efficiently. One example is the BLAS and LAPACK specifications used by NumPy to execute vector, matrix, and linear algebra operations.
You can learn more about BLAS and LAPACK in the tutorial:
We may install one of many different libraries that implement the BLAS and LAPACK specifications.
Most libraries that implement BLAS also implement LAPACK because LAPACK is built on top of BLAS. Therefore, we often refer to them simply as BLAS libraries.
Different libraries will have different capabilities and may optimize for different use cases or hardware.
Practically, we need to know which BLAS library is installed so that we can configure the number of threads used for some linear algebra operations.
We may also need to know in order to check if perhaps the wrong library is installed for our system, e.g. optimize for Intel CPUs when the system uses AMD CPUs.
How can we check which BLAS library is installed and used by NumPy?
Run loops using all CPUs, download your FREE book to learn how.
How to Check Which BLAS Library is Used By NumPy
There are two ways we can explore which BLAS library is installed and used by NumPy.
They are:
- Estimate based on how numpy was installed.
- Check the numpy configuration.
Let’s take a look at each approach in turn.
Estimate From NumPy Installation Method
When NumPy is installed, it will typically install a BLAS library as a dependency.
It does this so that the numpy installation can be customized specifically for the BLAS library that is installed.
There are many ways to install numpy. We can review some of the more common methods used to install numpy and look at the default BLAS library installed for each.
- Pip: Installs OpenBLAS by default.
- Homebrew: Installs OpenBLAS by default.
- MacPorts: Installs OpenBLAS by default.
- Conda: Installs MKL by default.
You can learn more about installing NumPy and BLAS libraries here:
Check NumPy Configuration
An alternate and preferred way to check which BLAS library is installed and used by NumPy is to check the NumPy configuration directly.
Because when numpy is installed it is compiled against a specific BLAS library, it records the BLAS library it was compiled against. We can then check this configuration at run time.
This can be achieved by calling the numpy.show_config() function.
The function takes no arguments and reports details of the system on which your numpy library was built.
Show libraries in the system on which NumPy was built. Print information about various resources (libraries, library directories, include directories, etc.) in the system on which NumPy was built.
— numpy.show_config API
Example of Checking the BLAS Library Used By NumPy
I installed NumPy on my current system using Homebrew.
This suggests that I am probably using OpenBLAS.
We can confirm this by checking their NumPy configuration directly.
The complete program is listed below.
1 2 3 |
# report the details of the blas library import numpy numpy.show_config() |
Running this program on my system reports that indeed I am using the OpenBLAS library.
What BLAS library do you have installed?
Post your output in the comments below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
blas_armpl_info: NOT AVAILABLE blas_mkl_info: NOT AVAILABLE blis_info: NOT AVAILABLE openblas_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/opt/openblas/lib'] language = c define_macros = [('HAVE_CBLAS', None)] blas_opt_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/opt/openblas/lib'] language = c define_macros = [('HAVE_CBLAS', None)] lapack_armpl_info: NOT AVAILABLE lapack_mkl_info: NOT AVAILABLE openblas_lapack_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/opt/openblas/lib'] language = c define_macros = [('HAVE_CBLAS', None)] lapack_opt_info: libraries = ['openblas', 'openblas'] library_dirs = ['/usr/local/opt/openblas/lib'] language = c define_macros = [('HAVE_CBLAS', None)] Supported SIMD extensions in this NumPy install: baseline = SSE,SSE2,SSE3 found = SSSE3,SSE41,POPCNT,SSE42,AVX,F16C,FMA3,AVX2 not found = AVX512F,AVX512CD,AVX512_KNL,AVX512_SKX,AVX512_CLX,AVX512_CNL,AVX512_ICL |
Free Concurrent NumPy Course
Get FREE access to my 7-day email course on concurrent NumPy.
Discover how to configure the number of BLAS threads, how to execute NumPy tasks faster with thread pools, and how to share arrays super fast.
Further Reading
This section provides additional resources that you may find helpful.
Books
- Concurrent NumPy in Python, Jason Brownlee (my book!)
Guides
- Concurrent NumPy 7-Day Course
- Which NumPy Functions Are Multithreaded
- Numpy Multithreaded Matrix Multiplication (up to 5x faster)
- NumPy vs the Global Interpreter Lock (GIL)
- ThreadPoolExecutor Fill NumPy Array (3x faster)
- Fastest Way To Share NumPy Array Between Processes
Documentation
- Parallel Programming with numpy and scipy, SciPi Cookbook, 2015
- Parallel Programming with numpy and scipy (older archived version)
- Parallel Random Number Generation, NumPy API
NumPy APIs
Concurrency APIs
- threading — Thread-based parallelism
- multiprocessing — Process-based parallelism
- concurrent.futures — Launching parallel tasks
Overwhelmed by the python concurrency APIs?
Find relief, download my FREE Python Concurrency Mind Maps
Takeaways
You now know how to check which BLAS library numpy is used on your system.
Do you have any questions?
Ask your questions in the comments below and I will do my best to answer.
Photo by Chiang Kuo on Unsplash
Do you have any questions?