GraphBLAS
GraphBLAS is a standard set of building blocks for writing graph algorithms as operations on sparse matrices and vectors. A graph (a set of vertices joined by edges) is stored as a matrix, and steps such as "find all neighbors" become matrix products.[1][2]
The name comes from the Basic Linear Algebra Subprograms (BLAS), the long-standing standard for dense linear algebra.[1] The main document is the GraphBLAS C API Specification, which defines how to use GraphBLAS from the C programming language. Version 2.1.0 was released on December 22, 2023.[1][2]
Graphs as sparse matrices
An adjacency matrix turns a graph into a table of numbers. For a graph with vertices, the matrix is , and the entry holds the weight of the edge from vertex to vertex .[3]
Most real graphs have few edges per vertex, so most entries have no value. A sparse matrix stores only the entries that exist.
With this layout, finding the neighbors of a set of vertices is the same as multiplying the adjacency matrix by a sparse vector that marks those vertices.[4] This is the basic idea behind GraphBLAS. Larger algorithms are built by chaining many such bulk matrix and vector operations.
Semirings
A semiring is a set of values with a pair of operations, used in place of ordinary addition and multiplication. Changing the semiring changes what a matrix product means for the graph, while the pattern of the computation stays the same.[3][5]
Generalized matrix multiplication
GraphBLAS defines the product of matrices and over a semiring as follows.[3]
- is the "multiply" operation, applied to each matching pair of entries.
- is the "add" operation, used to combine those results.
- runs only over indices where both and are stored, that is, over the intersection of the stored entries in row of and column of .
Written in shorthand, the product is . Because the operations are defined only over stored entries, the spec does not need to say how the identity of (its "zero") interacts with missing entries.[3]
Common semirings
Each semiring answers a different graph question.[5]
| Semiring | Values | Identity of | What a product finds | ||
|---|---|---|---|---|---|
| OR-AND (Boolean) | true, false | OR | AND | false | Which vertices can be reached |
| Plus-times (integer) | natural numbers | 0 | Number of paths | ||
| Plus-times (real) | real numbers | 0 | Strength of all paths | ||
| Min-plus | real numbers and | min | Shortest paths |
The min-plus case is the same as min-plus matrix multiplication, which works over the tropical semiring and is used for the shortest path problem.
Monoids and the relaxed definition
The "add" part of a GraphBLAS semiring is a Monoid: an operation that is associative and commutative and has an identity value. Examples include min (identity ), max (identity ), plus (identity 0), times (identity 1), and the logical operations OR and AND.[4] A monoid can also be used alone to reduce a matrix or vector to fewer values, like summing a column.[4]
In mathematics, a Semiring needs more than this. Multiplication must also have an identity, multiplying any value by the additive identity must give the additive identity, and multiplication must distribute over addition.[3] GraphBLAS drops some of these rules on purpose:
- Inputs may come from two different value types and the output from a third.[3]
- A multiplicative identity is not required.[3]
- The spec states that a GraphBLAS semiring may diverge from the strict definition, because some useful combinations are not true semirings.[2]
Objects
The C API is built on objects exposed to the programmer as opaque data types. A program handles them only through functions called methods, which create, change, copy, and destroy them.[2] This leaves each implementation free to choose its own internal storage.
The main object types are:[4][2]
- Matrices and vectors, which hold the graph and sets of vertices.
- Scalars, which hold a single value that may or may not be present.
- Types, which set the kind of value stored, such as Boolean, integer, or floating point.
- Unary and binary operators, which act on single values or pairs of values.
- Monoids and semirings, which bundle operators for reductions and products.
- Descriptors, which change how an operation treats its inputs and output.
Users can define their own types, operators, monoids, and semirings.[4]
Operations
GraphBLAS defines a small set of bulk operations on whole matrices and vectors. Most of them can take a mask and an accumulator, described in the next section. The exception is reduction to a scalar, which takes an accumulator but no mask.[4][3][2]
| Operation | What it does |
|---|---|
| mxm, mxv, vxm | Matrix-matrix, matrix-vector, and vector-matrix multiplication over a semiring |
| eWiseAdd | Element-wise operation on the union of stored entries |
| eWiseMult | Element-wise operation on the intersection of stored entries |
| extract | Copy out a submatrix or subvector |
| assign | Write into a submatrix or subvector |
| apply | Apply a function to every stored entry |
| select | Keep only entries that pass a test |
| reduce | Reduce each row to one value, giving a vector, or all entries to a scalar, using a monoid |
| transpose | Swap rows and columns |
| kronecker | Kronecker product of two matrices |
The union and intersection rules for the element-wise operations come from how they treat missing entries.[5] Both can act as graph union and graph intersection.
Bulk operations hand the library a lot of work at once, rather than one edge query at a time. Davis notes this gives room for tuned implementations on one thread, many threads, distributed systems, or GPUs.[4]
Masks, accumulators, and descriptors
Most GraphBLAS operations follow one pattern. A computed result passes through an optional accumulator and then an optional mask before it lands in the output.[4][3]
- is the output matrix.
- is the mask, which picks which entries of may change.
- is the accumulator, which merges old values of with new results.
The steps of one operation
For matrix multiplication, the pattern runs as follows.[4]
- Transpose or first if the descriptor asks for it.
- Compute the product .
- If an accumulator is given, form . Otherwise .
- Write into only where the mask allows.
Accumulator
The accumulator works like sparse matrix addition, but with any binary operator. The result keeps the union of entries in and , and the operator is applied only where both have an entry.[4]
Mask
A mask lets an entry of the output change only where the mask entry is true. Other output entries are protected.[4] Masks express the "if" test found inside many graph loops, such as skipping vertices that were already visited.[4]
There are two ways to handle entries outside the mask:[3]
- Merge mode leaves them as they were.
- Replace mode deletes them first, so the masked result replaces the old .
Descriptor
A descriptor is a set of settings attached to one call. It can:[4][6]
- transpose the first or second input matrix,
- use the complement of the mask, so that only entries outside the mask may change,
- use only the structure of the mask, ignoring its stored values,
- turn on replace mode for the output.
The complemented mask helps when only a few entries should be blocked. A small mask can be complemented instead of building a mostly full one.[6]
Example: breadth-first search
Breadth-first search visits a graph level by level from a start vertex. In GraphBLAS each level costs one masked vector-matrix product over the OR-AND semiring.[4]
The algorithm keeps two vectors. The frontier marks the vertices at the current level, and records the level at which each vertex was reached.[4]
- Put the start vertex in .
- Set to the current level at every vertex in , using as the mask.
- Compute over the OR-AND semiring, which finds all neighbors of the frontier.
- Store the result in using the complement of as the mask and replace mode. This keeps only vertices not yet visited.
- Reduce with the OR monoid. If no entry is true, stop. Otherwise add one to the level and go to step 2.
Steps 3 and 4 are a single call to the vxm operation.[4] The spec itself includes worked examples of breadth-first search, betweenness centrality, maximal independent set, and triangle counting.[2]
Execution model
A GraphBLAS program picks one of two execution modes when it starts.[2]
- In blocking mode, each method returns only after its computation is done and its outputs exist in memory.
- In nonblocking mode, a method may return as soon as its arguments are checked, before any computation has run.
Nonblocking mode lets an implementation queue operations, chain them, and fuse them into faster combined steps.[3] This is a form of deferred work similar to lazy evaluation. A program forces pending work to finish by calling the wait method.[2]
For a well-defined sequence with well-conditioned inputs, the two modes should give the same results, apart from floating-point round-off. Blocking mode is useful for debugging.[3]
History
The idea of writing graph algorithms in the language of linear algebra predates the standard. The authors of the C API design credit Jeremy Kepner and John Gilbert with developing that concept.[3]
| Date | Event |
|---|---|
| 2013 | Position paper at IEEE HPEC 2013 by Tim Mattson and 18 coauthors announces an open effort to define the standard[7] |
| 2016 | "Mathematical Foundations of the GraphBLAS" sets out the math behind the operations[8] |
| May 29, 2017 | C API version 1.0 (provisional) released at the GABB workshop[1] |
| November 14, 2017 | Version 1.1.0 (provisional)[1] |
| May 18, 2018 | Version 1.2.0[1] |
| September 25, 2019 | Version 1.3.0[1] |
| November 15, 2021 | Version 2.0.0[1] |
| December 22, 2023 | Version 2.1.0[1] |
The work is run by the GraphBLAS Forum, an open group. The forum states that its effort was inspired by the BLAS.[1]
Implementations and use
Several libraries implement the specification or build on it.
- SuiteSparse:GraphBLAS, by Timothy Davis, was the first fully compliant implementation and is the reference implementation. It is part of SuiteSparse and implements version 2.1.0.[4][1]
- The GraphBLAS Template Library (GBTL), from Carnegie Mellon University, Indiana University, and Pacific Northwest National Laboratory, was focused on correctness over speed as of 2019.[4]
- GraphBLAST, from UC Davis and Lawrence Berkeley National Laboratory, runs on NVIDIA GPUs.[9][1]
- MATLAB R2021a and later uses SuiteSparse:GraphBLAS for the product of two sparse matrices.[1]
- python-graphblas gives Python access and follows the C API 2.0 spec closely.[10]
- LAGraph builds high-level graph algorithms on top of GraphBLAS for users who do not want to write them from building blocks.[11]
- FalkorDB, a graph database formerly called RedisGraph, uses GraphBLAS inside.[1][4]
References
- The GraphBLAS: Welcome to the GraphBLAS Forum, GraphBLAS Forum, accessed 2024.
- The GraphBLAS C API Specification, Version 2.1.0, GraphBLAS Forum, 2023.
- Design of the GraphBLAS API for C, A. Buluç, T. Mattson, S. McMillan, J. Moreira, C. Yang, IEEE IPDPS Workshops, 2017.
- Algorithm 1000: SuiteSparse:GraphBLAS: Graph Algorithms in the Language of Sparse Linear Algebra, T. A. Davis, ACM Transactions on Mathematical Software, 2019.
- A linear algebraic approach for high-performance graph algorithms, G. Szárnyas, FOSDEM, 2020.
- Fundamentals, python-graphblas documentation, 2025.
- Standards for Graph Algorithm Primitives, T. Mattson et al., IEEE HPEC, 2013.
- Mathematical Foundations of the GraphBLAS, J. Kepner et al., IEEE HPEC, 2016.
- GraphBLAST: A High-Performance Linear Algebra-based Graph Framework on the GPU, C. Yang, A. Buluç, J. D. Owens, arXiv, 2019.
- python-graphblas, Python Package Index, 2025.
- LAGraph: Linear Algebra, Network Analysis Libraries, and the Study of Graph Algorithms, G. Szárnyas et al., arXiv, 2021.
