# GraphBLAS

**GraphBLAS**（Graph Basic Linear Algebra Subprograms，图基本线性代数子程序）是一套应用程序编程接口规范，定义了以线性代数语言表达图算法的标准构件，其基础是建立在半环代数结构之上的稀疏矩阵与向量运算。<sup>[1](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)</sup><sup> • </sup><sup>[2](https://www.sei.cmu.edu/projects/graphblas-a-programming-specification-for-graph-analysis/)</sup> 它由 GraphBLAS 论坛开发，这是一项横跨政府、研究中心、学术界与产业界的开放工作，其名称与宗旨均仿照面向稠密线性代数的基本线性代数子程序（BLAS）标准。<sup>[3](https://graphblas.org/)</sup><sup> • </sup><sup>[2](https://www.sei.cmu.edu/projects/graphblas-a-programming-specification-for-graph-analysis/)</sup>

| 关键事实 | 详情 |
|---|---|
| 是什么 | 一套定义在半环上的稀疏矩阵与向量运算标准 API，可用来表达种类繁多的图算法<sup>[1](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)</sup> |
| 核心洞见 | 当图用稀疏邻接矩阵或关联矩阵表示时，稀疏矩阵-向量乘法就是一步广度优先搜索；把标量运算推广为半环，便将原语扩展到一大类并行图算法<sup>[3](https://graphblas.org/)</sup> |
| C API 版本 | 1.0 版（暂行）于 2017 年 5 月 29 日发布；2.0.0 版于 2021 年 11 月 15 日发布；2.1.0 版于 2023 年 12 月 22 日发布<sup>[3](https://graphblas.org/)</sup> |
| 参考实现 | SuiteSparse:GraphBLAS（德克萨斯A&M大学），首个完全符合规范的发行版；IBM GraphBLAS 为第二个<sup>[4](https://graphblas.org/docs/GraphBLAS_Update_SC25.pdf)</sup> |
| 生产环境使用 | SuiteSparse:GraphBLAS 是 RedisGraph 数据库的图引擎，也是 MATLAB R2021a 内置的稀疏矩阵乘法，其中 `C=A*B` 比此前 MATLAB 版本快至多 30 倍<sup>[5](https://github.com/DrTimothyAldenDavis/GraphBLAS)</sup> |
| 语言绑定 | 包括 C、C++、Python、Go、Julia、MATLAB 和 PostgreSQL 封装等<sup>[4](https://graphblas.org/docs/GraphBLAS_Update_SC25.pdf)</sup> |

## 目的与数学基础

GraphBLAS 的工作基于这样一个观察：图算法可以写成稀疏线性代数。图中顶点之间的连接可以存放在邻接矩阵中——这便于分析，也可以存放在关联矩阵中——这往往更适合表示数据；二者通过矩阵乘法相互联系。因此，少量矩阵运算便能覆盖种类繁多的图，这种可组合性正是该标准的基础。<sup>[6](https://arxiv.org/abs/1606.05790)</sup>

这些运算通过半环得到推广。半环是一种代数结构，它将类幺半群的加法与一种乘法配对，使程序员可以用其他运算替代普通算术。改变底层半环会改变运算结果，因此同一个矩阵乘法原语可以视所选半环的不同，计算最短路径或连通性等等。<sup>[1](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)</sup><sup> • </sup><sup>[7](https://graphblas.org/docs/GraphBLAS_API_C_v2.1.0.pdf)</sup> 数学形式体系另见一份 GraphBLAS 数学规范，而 C API 规范假定硬件具备 IEEE 754（IEEE 754-2008）浮点运算能力。<sup>[8](https://graphblas.org/graphblas-api-cpp/)</sup><sup> • </sup><sup>[1](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)</sup>

## C API

GraphBLAS C API 定义了该标准的主要绑定。它向 C 程序员以不透明数据类型的形式暴露对象，只能通过创建、销毁和复制它们的方法来操作。<sup>[1](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)</sup> 不透明对象共四类：域（类型）、代数对象（算子、幺半群和半环）、集合（标量、向量、矩阵和掩码）以及描述符。<sup>[7](https://graphblas.org/docs/GraphBLAS_API_C_v2.1.0.pdf)</sup>

该 API 面向以 C99 为基础、扩展了基于类型和基于参数个数的函数多态性的 C 语言，其水平与 C11 的 `_Generic` 构造相当，并假定系统支持多线程执行所需的获取-释放内存序。<sup>[1](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)</sup> 程序以 `GrB_init()` 开始，以 `GrB_finalize()` 结束，这两个函数在每个应用中各自至多调用一次。<sup>[7](https://graphblas.org/docs/GraphBLAS_API_C_v2.1.0.pdf)</sup> 符合性被刻意设计得灵活：当平台无法支持某一特定类型或参数时，只要每个方法在绝大多数情况下都得到支持、且不支持的情况返回 `GrB_NOT_IMPLEMENTED` 错误码，实现仍可自称符合规范。<sup>[1](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)</sup>

C API 的版本历史：1.0 版（暂行）于 2017 年 5 月 29 日在 GABB 研讨会上发布，随后是 1.1.0（2017 年 11 月 14 日）、1.2.0（2018 年 5 月 18 日）、1.3.0（2019 年 9 月 25 日）、2.0.0（2021 年 11 月 15 日）和 2.1.0（2023 年 12 月 22 日）。<sup>[3](https://graphblas.org/)</sup> 2.1 版增加了类型内省，以及面向图神经网络和图数据库查询等新兴应用的增强功能。<sup>[9](https://graphblas.org/docs/GraphBLAS_Update-SC22-FINAL.pdf)</sup>

## C++ API

另一份 C++ API 规范正在制定中。它提供矩阵与向量的数据结构、广义矩阵乘法等算法，以及为 GraphBLAS 对象提供惰性求值的变换视图的视图机制。其概念设计使得其他库的数据结构只要定义少量用于插入、查找和迭代的定制点，便可用于 GraphBLAS 运算。<sup>[8](https://graphblas.org/graphblas-api-cpp/)</sup> 库若定义宏 `GRAPHBLAS_CPP_VERSION` 且其值至少为 `202207L`，即表示符合 0.1a 草案。<sup>[8](https://graphblas.org/graphblas-api-cpp/)</sup> 该规范归功于 Benjamin Brock、Scott McMillan、Aydın Buluç、Timothy Mattson 和 José Moreira，rgri 项目是其参考实现。<sup>[10](https://github.com/GraphBLAS/graphblas-api-cpp)</sup>

## 实现

SuiteSparse:GraphBLAS 由德克萨斯A&M大学的 Timothy A. Davis 开发，是该标准的完整实现，被称为首个完全符合规范的 GraphBLAS 发行版；IBM GraphBLAS 为第二个。<sup>[5](https://github.com/DrTimothyAldenDavis/GraphBLAS)</sup><sup> • </sup><sup>[4](https://graphblas.org/docs/GraphBLAS_Update_SC25.pdf)</sup> 其发行历史与规范同步：截至 v5.2.0 的版本符合 C API 1.3.0，自 v6.0.0 起的版本符合 2.0.0，自 9.0.0 起的版本符合 v2.1.0，并以 GxB 前缀的函数作为规范之外的扩展提供。<sup>[11](https://github.com/DrTimothyAldenDavis/GraphBLAS/blob/stable/README.md)</sup> 该库以 Apache-2.0 许可证发布，并获得 Intel、NVIDIA、Redis、MIT Lincoln Lab、MathWorks、IBM 和 Julia Computing 的支持。<sup>[5](https://github.com/DrTimothyAldenDavis/GraphBLAS)</sup>

GraphBLAS 论坛列出的其他实现与绑定包括：C++ GraphBLAS 模板库（GBTL，CMU-SEI/印第安纳/PNNL）、面向 GPU 的 GraphBLAST（UC Davis 与 LBNL）、MPI/C++ 组合式 BLAS（CombBLAS）、ALP/GraphBLAS（华为），以及面向 Python（python-graphblas、pygraphblas）、Go、Julia、MATLAB 和 PostgreSQL 的封装。<sup>[3](https://graphblas.org/)</sup><sup> • </sup><sup>[4](https://graphblas.org/docs/GraphBLAS_Update_SC25.pdf)</sup> 在单块 GPU 上，GraphBLAST 报告称平均比此前的 SuiteSparse 和 GBTL 实现至少快一个数量级，性能与 GPU 框架 Gunrock 和共享内存框架 Ligra 相当。<sup>[12](https://arxiv.org/abs/1908.01407)</sup>

## 算法库与基准测试

**LAGraph** 是一个库兼测试框架，汇集了构建在 GraphBLAS 之上的图算法，面向使用网络分析中常见高层图算法的用户；其性能已用 GAP 基准测试套件测量。<sup>[13](https://arxiv.org/abs/2104.01661)</sup><sup> • </sup><sup>[14](https://github.com/graphblas/lagraph)</sup>

GraphBLAS 实现已在两项广泛使用的基准测试工作中得到评估。太平洋西北国家实验室的一项研究使用 GAP 基准测试套件，将 GraphBLAS、Galois、BGL17 和 GraphIt 四种图分析方法与手工调优的实现进行比较；GAP 由 30 项测试组成，涵盖六种算法（广度优先搜索、单源最短路径、PageRank、介数中心性、连通分量和三角形计数），运行于五张拓扑特征各异的图上。<sup>[15](https://www.pnnl.gov/publications/evaluation-graph-analytics-frameworks-using-gap-benchmark-suite)</sup> LDBC Graphalytics 基准被 LDBC 描述为面向 Giraph、Spark GraphX 和 GraphBLAS 等图分析平台的工业级基准，其代码库中包含一个 GraphBLAS 参考实现。<sup>[16](https://ldbcouncil.org/benchmarks/graphalytics/)</sup>

## 优势与局限

Timothy A. Davis 对该方法的总结列出了以下优势：它避免了显式的“for all j in Adj(i)”邻接表循环，正如 `C=A*B` 取代了三重嵌套循环；其简洁的批量操作高层 API 为底层实现留出了优化空间；大多数并行图算法都可用线性代数表达；API 中的非阻塞模式可以融合内核并跳过中间结果的实例化。具体到 SuiteSparse:GraphBLAS，其并行性能可与高度调优的图库匹敌甚至胜出。<sup>[17](https://graphblas.org/GraphBLAS-Pointers/Slides/CSE21_Davis.pdf)</sup>

相应的局限在于：邻接表循环不可用，不过 GraphBLAS 可以与以顶点为中心的库并肩工作；有些算法难以表达，深度优先搜索和 Afforest 连通分量即为例证；而诸如 Gauss-Seidel PageRank 之类的完全异步方法也难以表达。<sup>[17](https://graphblas.org/GraphBLAS-Pointers/Slides/CSE21_Davis.pdf)</sup>

## References

1. [The GraphBLAS C API Specification, Version 2.0.0, graphblas.org](https://graphblas.org/docs/GraphBLAS_API_C_v2.0.0.pdf)
2. [GraphBLAS: A Programming Specification for Graph Analysis, CMU Software Engineering Institute](https://www.sei.cmu.edu/projects/graphblas-a-programming-specification-for-graph-analysis/)
3. [The GraphBLAS Forum, graphblas.org](https://graphblas.org/)
4. [The GraphBLAS is more than a set of specifications (SC'25 update), graphblas.org](https://graphblas.org/docs/GraphBLAS_Update_SC25.pdf)
5. [SuiteSparse:GraphBLAS repository, GitHub](https://github.com/DrTimothyAldenDavis/GraphBLAS)
6. [Mathematical Foundations of the GraphBLAS, arXiv:1606.05790](https://arxiv.org/abs/1606.05790)
7. [The GraphBLAS C API Specification, Version 2.1.0, graphblas.org](https://graphblas.org/docs/GraphBLAS_API_C_v2.1.0.pdf)
8. [GraphBLAS C++ API Specification v1.0, graphblas.org](https://graphblas.org/graphblas-api-cpp/)
9. [GraphBLAS Update, SC'22, graphblas.org](https://graphblas.org/docs/GraphBLAS_Update-SC22-FINAL.pdf)
10. [GraphBLAS/graphblas-api-cpp repository, GitHub](https://github.com/GraphBLAS/graphblas-api-cpp)
11. [SuiteSparse:GraphBLAS README (stable branch), GitHub](https://github.com/DrTimothyAldenDavis/GraphBLAS/blob/stable/README.md)
12. [GraphBLAST: A High-Performance Linear Algebra-based Graph Framework on the GPU, arXiv:1908.01407](https://arxiv.org/abs/1908.01407)
13. [LAGraph: Linear Algebra, Network Analysis Libraries, and the Study of Graph Algorithms, arXiv:2104.01661](https://arxiv.org/abs/2104.01661)
14. [GraphBLAS/LAGraph repository, GitHub](https://github.com/graphblas/lagraph)
15. [Evaluation of Graph Analytics Frameworks Using the GAP Benchmark Suite, PNNL](https://www.pnnl.gov/publications/evaluation-graph-analytics-frameworks-using-gap-benchmark-suite)
16. [LDBC Graphalytics Benchmark, Graph Data Council](https://ldbcouncil.org/benchmarks/graphalytics/)
17. [In summary: GraphBLAS strengths & limitations (CSE21 slides, T. Davis), graphblas.org](https://graphblas.org/GraphBLAS-Pointers/Slides/CSE21_Davis.pdf)

---
*Initially written Oct 15, 2026 · Edited: Oct 25, 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/graphblas

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