# OpenBLAS

**OpenBLAS** 是基础线性代数子程序（BLAS）的一个开源优化实现，基于后藤和茂（Kazushige Goto）的 GotoBLAS2 库的 1.13 BSD 许可版本，并同时附带 LAPACK 和 LAPACKE 线性代数 API。<sup>[1](https://www.openmathlib.org/OpenBLAS/)</sup><sup> • </sup><sup>[2](https://github.com/OpenMathLib/OpenBLAS)</sup> 它为多种 CPU 架构提供手工调优的汇编内核，通过 pthreads 或 OpenMP 实现多线程，并提供 C（CBLAS）和 Fortran（BLAS）两种接口。<sup>[3](https://www.openmathlib.org/OpenBLAS/docs/distributing/)</sup><sup> • </sup><sup>[4](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)</sup> 该项目位于 GitHub 上的 OpenMathLib 组织下，采用 BSD-3-Clause 许可证，由张先轶（Zhang Xianyi）和马丁·克罗克（Martin Kroeker）维护。<sup>[2](https://github.com/OpenMathLib/OpenBLAS)</sup><sup> • </sup><sup>[1](https://www.openmathlib.org/OpenBLAS/)</sup>

| 关键事实 | 详情 |
|---|---|
| 简介 | 一个基于 GotoBLAS2 1.13 BSD 版本的优化 BLAS 库，附带 LAPACK 和 LAPACKE<sup>[1](https://www.openmathlib.org/OpenBLAS/)</sup> |
| 许可证与主页 | BSD-3-Clause；在 github.com/OpenMathLib/OpenBLAS 开发（2023 年夏季从 xianyi 的个人仓库迁出）<sup>[2](https://github.com/OpenMathLib/OpenBLAS)</sup><sup> • </sup><sup>[1](https://www.openmathlib.org/OpenBLAS/)</sup> |
| 发布版本 | 0.3.33 于 2026 年 4 月 23 日发布；0.3.34 是 GitHub 上的最新版本<sup>[1](https://www.openmathlib.org/OpenBLAS/)</sup><sup> • </sup><sup>[5](https://github.com/OpenMathLib/OpenBLAS/releases)</sup> |
| 线程 | 默认使用 pthreads，OpenMP 为可选；默认支持最多 256 个核心，在 Linux x86-64 上通过 BIGNUMA=1 可实验性支持 1024 个核心和 128 个 NUMA 节点<sup>[3](https://www.openmathlib.org/OpenBLAS/docs/distributing/)</sup><sup> • </sup><sup>[4](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)</sup> |
| 整数接口 | 默认使用 LP64（32 位整数）；ILP64（64 位整数）构建使用 INTERFACE64=1 选项<sup>[3](https://www.openmathlib.org/OpenBLAS/docs/distributing/)</sup> |
| CPU 覆盖范围 | 包含 x86、x86_64、ARM（32 位和 64 位）、MIPS、Power、RISC-V、SPARC、z/架构（z/Architecture）、龙架构（LoongArch）的内核目录，以及遗留的 Alpha 和安腾（Itanium）内核<sup>[6](https://www.openmathlib.org/OpenBLAS/docs/developers/)</sup> |
| 默认安装路径 | 从源码通过 make install 安装时为 /opt/OpenBLAS<sup>[4](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)</sup> |

## 起源与算法

OpenBLAS 直接源自 GotoBLAS2，即后藤和茂所编写的库，该库在 2000 年代为高性能稠密线性代数树立了标准。<sup>[1](https://www.openmathlib.org/OpenBLAS/)</sup><sup> • </sup><sup>[7](https://wr.informatik.uni-hamburg.de/_media/teaching/sommersemester_2014/scc-14-bericht.pdf)</sup> 其性能核心是后藤和德克萨斯大学奥斯汀分校计算机科学家罗伯特·A·范德海恩（Robert A. van de Geijn）在 2008 年《ACM数学软件汇刊》论文《高性能矩阵乘法剖析》中描述的分块矩阵乘法（GEMM）算法。<sup>[6](https://www.openmathlib.org/OpenBLAS/docs/developers/)</sup><sup> • </sup><sup>[8](https://www.cs.utexas.edu/~flame/books/ACMTOMS.pdf)</sup> 该论文阐述了 GotoBLAS 中高性能矩阵-矩阵乘法背后的基本原理，在多级存储器架构模型下论证了设计决策的合理性，并报告了在广泛架构选择上接近峰值的性能。<sup>[8](https://www.cs.utexas.edu/~flame/books/ACMTOMS.pdf)</sup>

在 OpenBLAS 的源码树中，对 `dgemm` 的调用从 `interface/gemm.c` 出发，经过实现后藤算法的 `driver/level3/level3.c`，向下到达 `kernel/` 下各 CPU 专用的汇编内核。<sup>[6](https://www.openmathlib.org/OpenBLAS/docs/developers/)</sup> 每个受支持的 CPU 型号都有一个 KERNEL 文件来选择调优后的例程；例如，哈斯韦尔的 dgemm 内核为 `dgemm_kernel_4x8_haswell.S`。<sup>[6](https://www.openmathlib.org/OpenBLAS/docs/developers/)</sup> 将性能移植到新硬件意味着编写优化的汇编内核并调优缓存块大小 \( M_c \)、\( K_c \) 和 \( N_c \)。<sup>[6](https://www.openmathlib.org/OpenBLAS/docs/developers/)</sup>

## 构建与配置

默认构建使用 Make：`make` 自动检测宿主 CPU 并针对其优化，`make install` 默认将库安装到 `/opt/OpenBLAS` 下。<sup>[4](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)</sup> `TARGET` 标志可覆盖自动检测，交叉编译需要设置 `CC` 和 `FC` 交叉工具链、单独的 `HOSTCC` 以及显式的 `TARGET`；文档中给出的示例包括 ARM Cortex-A9 和龙芯3A（Loongson 3A）目标。<sup>[4](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)</sup> 也存在 CMake 构建，不过项目的再分发指南指出 CMake 构建仍处于实验阶段。<sup>[3](https://www.openmathlib.org/OpenBLAS/docs/distributing/)</sup>

**构建选项** 分为两类：影响用户接口的选项，如库名和符号名以及包含哪些 API；以及影响性能和运行时行为的选项，如线程和 CPU 专用代码路径。<sup>[3](https://www.openmathlib.org/OpenBLAS/docs/distributing/)</sup> 再分发指南建议保持启用 CBLAS、LAPACK 和 LAPACKE，始终附带 pkg-config 和 CMake 检测文件，并默认提供 LP64 接口。<sup>[3](https://www.openmathlib.org/OpenBLAS/docs/distributing/)</sup>

**线程与内存。** OpenBLAS 可使用 pthreads 或 OpenMP 构建，默认为 pthreads。<sup>[3](https://www.openmathlib.org/OpenBLAS/docs/distributing/)</sup> 多线程时，库使用一个内存缓冲区来通信和整理原始矩阵子范围的结果；自 2000 年代初的原始 GotoBLAS 以来，该缓冲区在 x86_64 上默认为 32<<20 字节（32 MB），在 PowerPC 上翻倍，超过约 30000x30000 的问题可能需要更大的值。<sup>[9](https://github.com/OpenMathLib/OpenBLAS/blob/develop/Makefile.rule)</sup> 缓冲区不足通常表现为相关 scal 内核中的崩溃。<sup>[9](https://github.com/OpenMathLib/OpenBLAS/blob/develop/Makefile.rule)</sup> 单线程构建仍可通过 `USE_LOCKING=1` 对并发调用者保持线程安全。<sup>[9](https://github.com/OpenMathLib/OpenBLAS/blob/develop/Makefile.rule)</sup>

**DYNAMIC_ARCH。** 不在构建时固定一个 CPU 目标，`DYNAMIC_ARCH=1` 将多个优化代码路径构建到一个二进制文件中，并在运行时从中选择，项目自己的 Windows 二进制文件就是这样构建的（使用 `NUM_THREADS=64 TARGET=GENERIC DYNAMIC_ARCH=1`）。<sup>[9](https://github.com/OpenMathLib/OpenBLAS/blob/develop/Makefile.rule)</sup><sup> • </sup><sup>[10](https://www.openmathlib.org/OpenBLAS/docs/install/)</sup>

## 安装与使用

几乎每个包管理器都提供 OpenBLAS。<sup>[10](https://www.openmathlib.org/OpenBLAS/docs/install/)</sup> 在 Debian、Ubuntu、Mint 和 Kali 上，开发包为 `libopenblas-dev`；openSUSE 和 Fedora 使用 `openblas-devel`，Arch 使用 `openblas`。<sup>[10](https://www.openmathlib.org/OpenBLAS/docs/install/)</sup> Linux 发行版通常将包分为两个：库本身，以及包含头文件、pkg-config 和 CMake 文件的 `-dev`/`-devel` 包；两者都需要才能针对该库构建。<sup>[10](https://www.openmathlib.org/OpenBLAS/docs/install/)</sup> 在 Debian 系系统上，可通过 `libblas.so.3` 的 `update-alternatives` 机制将 OpenBLAS 设为系统默认 BLAS。<sup>[10](https://www.openmathlib.org/OpenBLAS/docs/install/)</sup> Fedora 不提供 OpenBLAS 的 pkg-config 文件，而是引导开发者使用 FlexiBLAS，后者在 Fedora 上以 OpenBLAS 作为默认后端。<sup>[10](https://www.openmathlib.org/OpenBLAS/docs/install/)</sup> Windows 是项目自身发布二进制文件的唯一平台，使用 MinGW 构建并通过 GitHub Releases 分发。<sup>[10](https://www.openmathlib.org/OpenBLAS/docs/install/)</sup>

应用程序通过 `-lopenblas` 链接（多线程构建还需 `-lpthread`，调用 LAPACK 例程时需 `-lgfortran`），或通过安装的 `openblas.pc` pkg-config 文件链接。<sup>[4](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)</sup> 从 C 代码调用时，CBLAS 接口（如 `cblas_dgemm`）是更可移植的选择，因为直接调用 Fortran 接口需要处理编译器特定的符号命名，如 `dgemm_` 中的尾随下划线。<sup>[4](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)</sup>

**在科学 Python 生态中的角色。** NumPy 的构建系统按典型顺序尝试已知的 BLAS 库：MKL、Accelerate、OpenBLAS、FlexiBLAS、BLIS 和普通的 `libblas`/`liblapack`，使用找到的第一个合适库；该顺序可通过 `blas-order` 和 `lapack-order` 构建选项更改。<sup>[11](https://numpy.org/doc/stable/building/blas_lapack.html)</sup> NumPy 默认使用 LP64 接口，并使用 `use-ilp64` 构建选项链接 64 位整数 BLAS 和 LAPACK。<sup>[11](https://numpy.org/doc/stable/building/blas_lapack.html)</sup>

## 相对于替代方案的性能

OpenBLAS 是基准测试中比较的几种优化 BLAS 实现之一，其他还包括 Intel oneMKL、BLIS（其自身在一份 PNNL 报告中被描述为 GotoBLAS2 的较新重构）和 ATLAS。<sup>[12](https://www.pnnl.gov/main/publications/external/technical_reports/PNNL-36775.pdf)</sup><sup> • </sup><sup>[13](https://www.sandia.gov/research/publications/details/replicated-computational-results-rcr-report-for-blis-a-framework-for-rapidl-2015-05-01/)</sup> 结果取决于 CPU 厂商。在至强E5-2697 v4 系统上进行的一项 Intel 比较发现，oneMKL 在几乎所有 R 基准测试中优于 OpenBLAS 0.2.14，唯一例外是 45x45 矩阵上的埃斯库菲耶方法（Escoufier's method）。<sup>[14](https://www.intel.com/content/www/us/en/developer/articles/technical/performance-comparison-of-openblas-and-intel-math-kernel-library-in-r.html)</sup> 在 AMD Zen2 上，JAIST 的一项研究测得 OpenBLAS 和 BLIS 的单核性能约为 MKL 的 1.25 倍。<sup>[15](https://dspace02.jaist.ac.jp/dspace/bitstream/10119/18741/5/paper.pdf)</sup> BLIS 项目自己的性能文档将 OpenBLAS、MKL 和 BLIS 置于同一比较集中，BLIS 除 `trsm` 外具有竞争力。<sup>[16](https://github.com/flame/blis/blob/master/docs/Performance.md)</sup> 由于结果因处理器和操作而异，这些来源中的实用建议是针对具体工作负载进行基准测试。<sup>[14](https://www.intel.com/content/www/us/en/developer/articles/technical/performance-comparison-of-openblas-and-intel-math-kernel-library-in-r.html)</sup>

## 近期发展

0.3.x 系列继续频繁发布小版本。2026 年 4 月 23 日发布的 0.3.33 版在核心数超过 256 时自动启用 BIGNUMA 设置，并在参考LAPACK 3.13.0 发布前导入了其更新。<sup>[5](https://github.com/OpenMathLib/OpenBLAS/releases)</sup> 0.3.34 版修复了并发调用 3 级 BLAS 函数之间以及 GETRF 中潜在的竞态条件，为 GETRS、LAUUM 和 TRTRS 等例程添加了多线程阈值，并为龙架构、RISC-V（包括专用的 SiFive U74 目标）和基于 Apple SME 的 SGEMM 添加了优化内核。<sup>[5](https://github.com/OpenMathLib/OpenBLAS/releases)</sup> 内核树覆盖 x86_64、ARM64、RISC-V、Power、MIPS、SPARC、z/架构和龙架构，以及从 GotoBLAS 继承的遗留 Alpha 和安腾内核，反映了该库作为跨架构厂商中立 BLAS 的角色。<sup>[6](https://www.openmathlib.org/OpenBLAS/docs/developers/)</sup>

## References

1. [OpenBLAS: An optimized BLAS library, OpenMathLib](https://www.openmathlib.org/OpenBLAS/)
2. [OpenMathLib/OpenBLAS repository, GitHub](https://github.com/OpenMathLib/OpenBLAS)
3. [Redistributing OpenBLAS, OpenBLAS documentation](https://www.openmathlib.org/OpenBLAS/docs/distributing/)
4. [User manual, OpenBLAS documentation](https://www.openmathlib.org/OpenBLAS/docs/user_manual/)
5. [Releases, OpenMathLib/OpenBLAS, GitHub](https://github.com/OpenMathLib/OpenBLAS/releases)
6. [Developer manual, OpenBLAS documentation](https://www.openmathlib.org/OpenBLAS/docs/developers/)
7. [Student Cluster Competition 2014 report, University of Hamburg](https://wr.informatik.uni-hamburg.de/_media/teaching/sommersemester_2014/scc-14-bericht.pdf)
8. [Goto, K. and van de Geijn, R. A. (2008). Anatomy of High-Performance Matrix Multiplication. ACM Trans. Math. Softw. 34(3), Article 12](https://www.cs.utexas.edu/~flame/books/ACMTOMS.pdf)
9. [OpenBLAS Makefile.rule, OpenMathLib/OpenBLAS, GitHub](https://github.com/OpenMathLib/OpenBLAS/blob/develop/Makefile.rule)
10. [Install OpenBLAS, OpenBLAS documentation](https://www.openmathlib.org/OpenBLAS/docs/install/)
11. [BLAS and LAPACK, NumPy v2.5 Manual](https://numpy.org/doc/stable/building/blas_lapack.html)
12. [OpenBLAS, PNNL-36775 technical report](https://www.pnnl.gov/main/publications/external/technical_reports/PNNL-36775.pdf)
13. [Replicated computational results report for "BLIS: A Framework for Rapidly Instantiating BLAS Functionality", Sandia National Laboratories](https://www.sandia.gov/research/publications/details/replicated-computational-results-rcr-report-for-blis-a-framework-for-rapidl-2015-05-01/)
14. [Performance Comparison of OpenBLAS and Intel oneAPI Math Kernel Library (oneMKL) in R, Intel](https://www.intel.com/content/www/us/en/developer/articles/technical/performance-comparison-of-openblas-and-intel-math-kernel-library-in-r.html)
15. [Performance comparison of linear algebra libraries on Zen2, JAIST](https://dspace02.jaist.ac.jp/dspace/bitstream/10119/18741/5/paper.pdf)
16. [BLIS Performance documentation, FLAME/blis, GitHub](https://github.com/flame/blis/blob/master/docs/Performance.md)

---
*Initially written Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Linear and multilinear algebra › Numerical linear algebra › Numerical linear algebra software

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/openblas

English original: https://www.edgepedia.org/openblas
