liveBook · Manning

BLAS

As explained in Fast Python: High performance techniques for large datasets

BLAS is a standard interface and collection of low-level routines for efficient vector and matrix operations in numerical computing.

BLAS is a standard interface and collection of low-level routines for array and matrix operations, including vector addition and matrix multiplication. Numerical libraries such as NumPy depend on BLAS beneath higher-level algorithms. section 4.3.1

The implementation matters for performance. Netlib BLAS is generally nonthreaded and slow on modern systems, while OpenBLAS and Intel MKL provide threaded alternatives. Threading changes how CPU resources should be allocated: multiprocessing can overcommit cores when BLAS also uses multiple threads. section 4.3.1 section 4.3.2

Use the following workflow to identify and tune the BLAS implementation behind NumPy:

  • Inspect NumPy’s reported configuration with np.show_config(). section 4.3.1
  • If the output is unclear, inspect library files, package metadata, and symbolic links to determine the linked implementation. section 4.3.1
  • Replace slow Netlib BLAS with OpenBLAS or MKL when performance requires it, then verify that NumPy links to the intended library. section 4.3.2
  • Account for BLAS threading when choosing between threads, processes, and available CPU cores. section 4.3.1

Checking a linked implementation

Running np.show_config() may reveal BLAS and LAPACK library directories, but ambiguous package names can require inspecting files such as libcblas.so.3 to discover a link to libmkl_rt.so. section 4.3.1

Figure 4.11 The NumPy stack, including library dependencies

The NumPy stack diagram places BLAS and LAPACK beneath higher-level numerical functionality. section 4.3.1

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Explains core operations, implementation choices, linkage inspection, and threading consequences without detailing BLAS algorithms.
Examples
Uses vector addition, matrix multiplication, np.show_config(), shared-library links, and Anaconda MKL installation.
What it assumes
Assumes familiarity with NumPy and Python distributions while introducing dependency inspection and threaded-library resource effects.
What you can do after
Configure and diagnose NumPy’s BLAS backend using np.show_config(), package inspection, and OpenBLAS or MKL installation.
How it connects
Connects BLAS to LAPACK, NumPy, SciPy, OpenBLAS, Intel MKL, and multiprocessing.

Also explained in

Compare how 2 books explain BLAS →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.