Search topics and sections

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 nn vertices, the matrix AA is n×nn \times n, and the entry A(i,j)A(i,j) holds the weight of the edge from vertex ii to vertex jj.[3]

Most real graphs have few edges per vertex, so most entries have no value. A sparse matrix stores only the entries that exist.

A directed graph and its sparse adjacency matrix 1 2 3 4 1 1 1 1 1 1 2 3 4 to (column j) 1 2 3 4 from (row i) blank = no stored entry
A directed graph and its sparse adjacency matrix AA, where A(i,j)A(i,j) is stored only when there is an edge from vertex ii to vertex jj.

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 AA and BB over a semiring as follows.[3]

C(i,j)=⨁kA(i,k)⊗B(k,j)C(i,j) = \bigoplus_{k} A(i,k) \otimes B(k,j)
  • ⊗\otimes is the "multiply" operation, applied to each matching pair of entries.
  • ⊕\oplus is the "add" operation, used to combine those results.
  • kk runs only over indices where both A(i,k)A(i,k) and B(k,j)B(k,j) are stored, that is, over the intersection of the stored entries in row ii of AA and column jj of BB.

Written in shorthand, the product is C=A⊕.⊗BC = A \oplus.\otimes B. Because the operations are defined only over stored entries, the spec does not need to say how the identity of ⊕\oplus (its "zero") interacts with missing entries.[3]

Common semirings

Each semiring answers a different graph question.[5]

Semiring Values ⊕\oplus ⊗\otimes Identity of ⊕\oplus What a product finds
OR-AND (Boolean) true, false OR AND false Which vertices can be reached
Plus-times (integer) natural numbers ++ ×\times 0 Number of paths
Plus-times (real) real numbers ++ ×\times 0 Strength of all paths
Min-plus real numbers and +∞+\infty min ++ +∞+\infty 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 +∞+\infty), max (identity −∞-\infty), 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]

C⟨M⟩=C⊙(A⊕.⊗B)C\langle M \rangle = C \odot (A \oplus.\otimes B)
  • CC is the output matrix.
  • MM is the mask, which picks which entries of CC may change.
  • ⊙\odot is the accumulator, which merges old values of CC with new results.

The steps of one operation

For matrix multiplication, the pattern runs as follows.[4]

  1. Transpose AA or BB first if the descriptor asks for it.
  2. Compute the product T=A⊕.⊗BT = A \oplus.\otimes B.
  3. If an accumulator is given, form Z=C⊙TZ = C \odot T. Otherwise Z=TZ = T.
  4. Write ZZ into CC only where the mask allows.
Mask and accumulator pipeline of a GraphBLAS operation A B transpose? transpose? T = A ⊕.⊗ B Z = C ⊙ T old C write Z into C where mask M allows new C merge: entries outside mask keep old values replace: entries outside mask are deleted descriptor semiring product accumulator (optional) mask (optional, may be complemented)
One GraphBLAS operation: optional transposes, a semiring product TT, an optional accumulator ⊙\odot that merges with the old CC, and an optional mask MM that controls which entries of CC change.

Accumulator

The accumulator works like sparse matrix addition, but with any binary operator. The result keeps the union of entries in CC and TT, 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 CC.

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]

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 qq marks the vertices at the current level, and vv records the level at which each vertex was reached.[4]

  1. Put the start vertex ss in qq.
  2. Set vv to the current level at every vertex in qq, using qq as the mask.
  3. Compute qTAq^T A over the OR-AND semiring, which finds all neighbors of the frontier.
  4. Store the result in qq using the complement of vv as the mask and replace mode. This keeps only vertices not yet visited.
  5. Reduce qq with the OR monoid. If no entry is true, stop. Otherwise add one to the level and go to step 2.
Breadth-first search by levels in GraphBLAS 1 2 3 4 Level 1 Level 2 Level 3 Level Frontier q qTA (OR-AND) After mask ¬v 1 {1} {2, 3} {2, 3} 2 {2, 3} {4} {4} 3 {4} {1} { } stop Vertex 1 visited Result v = [1, 2, 2, 3]
Breadth-first search from vertex 1: each level is one product qTAq^T A over the OR-AND semiring, masked by the complement of the visited vector vv; the search stops when the frontier is empty.

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

  1. The GraphBLAS: Welcome to the GraphBLAS Forum, GraphBLAS Forum, accessed 2024.
  2. The GraphBLAS C API Specification, Version 2.1.0, GraphBLAS Forum, 2023.
  3. Design of the GraphBLAS API for C, A. Buluç, T. Mattson, S. McMillan, J. Moreira, C. Yang, IEEE IPDPS Workshops, 2017.
  4. Algorithm 1000: SuiteSparse:GraphBLAS: Graph Algorithms in the Language of Sparse Linear Algebra, T. A. Davis, ACM Transactions on Mathematical Software, 2019.
  5. A linear algebraic approach for high-performance graph algorithms, G. Szárnyas, FOSDEM, 2020.
  6. Fundamentals, python-graphblas documentation, 2025.
  7. Standards for Graph Algorithm Primitives, T. Mattson et al., IEEE HPEC, 2013.
  8. Mathematical Foundations of the GraphBLAS, J. Kepner et al., IEEE HPEC, 2016.
  9. GraphBLAST: A High-Performance Linear Algebra-based Graph Framework on the GPU, C. Yang, A. Buluç, J. D. Owens, arXiv, 2019.
  10. python-graphblas, Python Package Index, 2025.
  11. LAGraph: Linear Algebra, Network Analysis Libraries, and the Study of Graph Algorithms, G. Szárnyas et al., arXiv, 2021.

Figure

Subtopics