# OpenBLAS — Optimized Open-Source BLAS Library > OpenBLAS is an optimized implementation of the Basic Linear Algebra Subprograms (BLAS) and LAPACK APIs. It provides hand-tuned assembly kernels for dozens of CPU architectures, delivering near-vendor performance for numerical computing. ## Install Save in your project root: # OpenBLAS — Optimized Open-Source BLAS Library ## Quick Use ```bash # Ubuntu/Debian sudo apt install libopenblas-dev # macOS brew install openblas # Build from source git clone https://github.com/OpenMathLib/OpenBLAS.git cd OpenBLAS make -j$(nproc) sudo make install PREFIX=/usr/local ``` ```python # NumPy automatically uses OpenBLAS when linked import numpy as np a = np.random.rand(1000, 1000) b = np.random.rand(1000, 1000) c = a @ b # Uses OpenBLAS DGEMM under the hood ``` ## Introduction OpenBLAS is a free, open-source implementation of the BLAS and LAPACK linear algebra interfaces. Originally forked from GotoBLAS2, it includes hand-optimized assembly kernels that make it competitive with proprietary libraries like Intel MKL on many workloads. NumPy, SciPy, R, Julia, and Octave all use OpenBLAS as a default backend. ## What OpenBLAS Does - Implements the full BLAS Level 1, 2, and 3 API for vector, matrix-vector, and matrix-matrix operations - Provides a complete LAPACK implementation for linear solvers, eigenvalue, and SVD routines - Includes hand-tuned assembly kernels for x86-64, ARM, POWER, RISC-V, and other architectures - Supports multi-threaded execution with pthreads or OpenMP for parallel linear algebra - Offers a CBLAS C interface alongside the traditional Fortran interface ## Architecture Overview OpenBLAS detects the CPU architecture at build time and selects the optimal kernel from a library of hand-written assembly routines. For matrix multiplication (DGEMM), it partitions matrices into blocks sized to fit L1/L2 cache, then dispatches to SIMD-optimized micro-kernels. Thread parallelism divides work across cores at the block level. Runtime CPU detection is also supported, producing a single binary that dynamically picks the best kernel for the host processor. ## Self-Hosting & Configuration - Install from your OS package manager or build from source with make - Set TARGET=HASWELL (or your CPU) for architecture-specific optimization - Control thread count with the OPENBLAS_NUM_THREADS environment variable - Use NO_LAPACK=1 during build to compile only BLAS routines if LAPACK is not needed - Link with -lopenblas; the library is a drop-in replacement for reference BLAS and LAPACK ## Key Features - Hand-optimized assembly kernels for all major CPU families including x86, ARM, and RISC-V - Drop-in replacement for reference BLAS, LAPACK, Intel MKL, and Apple Accelerate - Runtime CPU detection for portable multi-architecture binaries - Configurable threading with pthreads or OpenMP backends - Default BLAS backend for NumPy, SciPy, Julia, R, and GNU Octave ## Comparison with Similar Tools - **Intel MKL (oneMKL)** — Fastest on Intel hardware; proprietary license, limited to x86 - **Apple Accelerate** — Tuned for Apple Silicon; macOS only, not portable - **BLIS** — Modern BLAS framework with pluggable micro-kernels; fewer prebuilt targets - **ATLAS** — Auto-tuned BLAS; slower builds and fewer architecture optimizations than OpenBLAS - **Reference BLAS (Netlib)** — Correct but unoptimized; useful only for validation and testing ## FAQ **Q: How does OpenBLAS compare to Intel MKL in performance?** A: On Intel CPUs, MKL is typically faster by a few percent. On AMD, ARM, and other architectures, OpenBLAS often matches or exceeds MKL. OpenBLAS is free and cross-platform. **Q: Does NumPy use OpenBLAS by default?** A: Yes. The standard pip-installed NumPy wheels are linked against OpenBLAS on Linux and Windows. **Q: How do I control the number of threads?** A: Set the OPENBLAS_NUM_THREADS environment variable before launching your application. **Q: Can OpenBLAS run on ARM servers?** A: Yes. OpenBLAS has optimized kernels for ARMv8 (AArch64) including Cortex-A72, Neoverse, and Apple M-series processors. ## Sources - https://github.com/OpenMathLib/OpenBLAS - https://www.openblas.net/ --- Source: https://tokrepo.com/en/workflows/asset-31f135bb Author: AI Open Source