원시데이터 수집 시스템
선정목록으로

Revisiting Sparse Matrix Coloring and Bicoloring

관련 필름·전자재료 · (16) CPI(투명 폴리이미드)

기본 정보

저자
  1. Montoison, Alexis
  2. Dalle, Guillaume
  3. Assefaw Gebremedhin
DOI
10.13140/rg.2.2.22332.55680
저널
–
발행년도
2025
발행기관
–
피인용수
0
라이선스
0
논문 유형
–
언어
–
원문 페이지
https://doi.org/10.13140/rg.2.2.22332.55680
토픽
Color Science and Applications
OpenAlex ID
W6903826673

평가 내용

관련도
관련
사업분야
필름·전자재료 · (16) CPI(투명 폴리이미드)
부 분야
–
R&D 측면
–
확신도
–
근거 용어
–
판단 근거
임베딩 유사도 기반 평가로 '필름·전자재료 > CPI(투명 폴리이미드)' 분야에 선정된 논문입니다.
R&D 활용 포인트
–
평가 입력
–

초록

초록이 없습니다.

본문 111,218자

본문 펼치기
REVISITING SPARSE MATRIX COLORING AND BICOLORING ALEXIS MONTOISON <sup>_∗_</sup>, GUILLAUME DALLE <sup>_†_</sup>, AND ASSEFAW GEBREMEDHIN <sup>_‡_</sup> Abstract. Sparse matrix coloring and bicoloring are fundamental building blocks of sparse automatic differentiation. Bicoloring is particularly advantageous for rectangular Jacobian matrices with at least one dense row and column. Indeed, in such cases, unidirectional row or column coloring demands a number of colors equal to the number of rows or columns. We introduce a new strategy for bicoloring that encompasses both direct and substitution-based decompression approaches. Our method reformulates the two variants of bicoloring as star and acyclic colorings of an augmented symmetric matrix. We extend the concept of neutral colors, previously exclusive to bicoloring, to symmetric colorings, and we propose a post-processing routine that neutralizes colors to further reduce the overall color count. We also present the Julia package `SparseMatrixColorings.jl`, which includes these new bicoloring algorithms alongside all standard coloring methods for sparse derivative matrix computation. Compared to `ColPack`, the Julia package also offers enhanced implementations for star and acyclic coloring, vertex ordering, as well as decompression. Key words. graph coloring, bicoloring, post-processing, sparsity patterns, Jacobian, Hessian, automatic differentiation, Julia AMS subject classifications. 05C15, 65F50, 65D25, 68R10, 90C06 1. Introduction. 1.1. Context and motivation. Modern scientific computing makes heavy use of automatic differentiation (AD) to obtain derivatives of computer programs [6]. Such derivatives are relevant in a wide variety of settings, from differential equations and nonlinear optimization to machine learning. Whenever the objects of interest are sparse matrices (Jacobians or Hessians), their computation can be accelerated significantly [26]. However, reaping the benefits of sparsity comes with increased algorithmic and implementation challenges. Consider a function _f_ : R <sup>_n_</sup> _→_ R <sup>_m_</sup> and its Jacobian matrix _J_ = _∂f_ ( _x_ ) at a point _x_ . For roughly the same cost as the evaluation of _f_, forward-mode AD evaluates a single Jacobian-vector product _u �→_ _Ju_, while reverse-mode AD evaluates a single VectorJacobian product _v_ _�→_ _v_ <sup>_⊤_</sup> _J_ . Importantly, this is obtained without ever materializing the matrix _J_ . Taking the seed _u_ = _ej_ (resp. _v_ = _ei_ ) to be a basis vector of the input space (resp. output space) lets us recover the _j_ -th column (resp. _i_ -th row) of the Jacobian. One can then iterate through basis vectors and reconstruct the full Jacobian, either column-wise or row-wise. The complexity of this recovery, expressed in number of calls to _f_, scales either with the input dimension _n_ or with the output dimension _m_ . Luckily, when the Jacobian is sparse, focusing on the non-zero entries often speeds things up. For instance, if the non-zeros in columns _j_ 1 and _j_ 2 never overlap at any row, they can be recovered together in a single product _J_ ( _ej_ 1 + _ej_ 2) without the non-zero entries getting mixed up. Making this insight actionable requires solving a _matrix_ _coloring_ _problem_ [20], which determines the sets of columns or rows of _J_ that can be evaluated simultaneously. The number of distinct colors obtained corresponds to the number of seeds required to recover all non-zero entries of _J_ . The recovery complexity then scales with the number of colors _c_, rather than _n_ or _m_ . _∗_ Argonne National Laboratory, IL, USA. E-mail: `[amontoison@anl.gov](mailto:amontoison@anl.gov)` _†_ LVMT, ENPC, Institut Polytechnique de Paris, Univ Gustave Eiffel, Marne-la-Vallée, France. E-mail: `[guillaume.dalle@enpc.fr](mailto:guillaume.dalle@enpc.fr)` _‡_ Washington State University, School of EECS, WA, USA. E-mail: `[assefaw.gebremedhin@wsu.edu](mailto:assefaw.gebremedhin@wsu.edu)` Version of May 26, 2025. 1 2 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] In some cases, like for banded matrices, non-overlapping columns and rows are easy to find, and the number of colors remains much lower than the dimension (scaling with the number of bands). But when a few columns or rows exhibit dense structures, the number of colors required can increase significantly. This justifies a shift from unidirectional to bidirectional coloring, or _bicoloring_ [11, 30], which handles columns and rows jointly by combining reverse-mode and forward-mode AD. We illustrate this idea on a rectangle matrix in Figure 1.1, where a dense row and a dense column impose a significant burden on any one-sided coloring scheme. As seen in Figure 1.2, Fig. 1.1: Row coloring (left) and column coloring (right) of a rectangle matrix, requiring the same number of colors as the matrix dimensions (respectively 6 and 12 in this case). bicoloring offers a solution to this problem by assigning colors to a subset of both columns and rows: colored columns to be computed in forward mode and colored rows to be computed in reverse mode. Fig. 1.2: Bicoloring of a rectangle matrix, requiring only 2 colors for the rows (left) and 2 colors for the columns (right). In the central figure, each nonzero coefficient is colored using its row’s color and its column’s color, when it is not neutral. 1.2. Applications. In certain optimization problems, the structure of the Jacobian can make unidirectional coloring inefficient. This subsection highlights cases where bidirectional coloring leads to substantial improvements in the computation of Jacobians. 1.2.1. Nonlinear least-squares problems. In the Gauss-Newton method [5] for solving min _x∈_ R <sup>_n_</sup> 2 <sup><u>1</u></sup> <sup>_∥F_</sup> <sup>(</sup> <sup>_x_</sup> <sup>)</sup> <sup>_∥_</sup> <sup>2,</sup> <sup>with</sup> <sup>_F_</sup> <sup>: R</sup> <sup>_n_</sup> <sup>_→_</sup> <sup>R</sup> <sup>_m_</sup> <sup>,</sup> <sup>one</sup> <sup>must</sup> <sup>solve</sup> <sup>a</sup> <sup>sequence</sup> <sup>of</sup> <sup>linear</sup> least-squares subproblems. At iteration _k_, the subproblem is min _d∈_ R <sup>_n_</sup> 21 <sup>_∥J_</sup> <sup>(</sup> <sup>_xk_</sup> <sup>)</sup> <sup>_d_</sup> <sup>+</sup> <sup>_F_</sup> <sup>(</sup> <sup>_xk_</sup> <sup>)</sup> <sup>_∥_</sup> <sup>2</sup> <sup>_,_</sup> where _J_ ( _x_ ) _∈_ R <sup>_m×n_</sup> is the Jacobian of _F_ at _x_ . When _m ≫_ _n_, column coloring with forward-mode AD is typically used for efficient Jacobian computation. However, the presence of a dense row, due to a residual involving all variables (such as normalization constraints or global coupling terms) renders column coloring inefficient, as the entire row must be recovered regardless of compression. While row coloring with reverse-mode AD is an alternative, it tends to be inefficient when _m_ is much larger than _n_ (due to a large number of row colors). Bicoloring can improve performance by recovering sparse columns using forward-mode AD and a few dense rows using reverse-mode AD. [toc] Revisiting sparse matrix coloring and bicoloring 3 1.2.2. Equality-constrained optimization problems. For optimization problems of the form _x_ min _∈_ R <sup>_n ϕ_</sup> <sup>(</sup> <sup>_x_</sup> <sup>)</sup> subject to _c_ ( _x_ ) = 0 _,_ where _ϕ_ : R <sup>_n_</sup> _→_ R and _c_ : R <sup>_n_</sup> _→_ R <sup>_m_</sup>, the Jacobian _J_ ( _x_ ) _∈_ R <sup>_m×n_</sup> of the constraints _c_ is essential for forming the sequence of linear systems encountered in Newton-based interior-point methods [45]. In particular, the linear system at iteration _k_ is given by the Karush–Kuhn–Tucker conditions: - _∇_ <sup>2</sup> _xx_ <sup>_L_</sup> <sup>(</sup> <sup>_x_</sup> _k_ <sup>_, y_</sup> _k_ <sup>)</sup> _J_ ( _xk_ ) <sup>_⊤_</sup> _J_ ( _xk_ ) 0 ��∆ _x_ = _−_ ∆ _y_ - _∇xL_ ( _xk, yk_ )� _,_ _c_ ( _xk_ ) where _L_ ( _x, y_ ) = _ϕ_ ( _x_ ) _−_ _y_ <sup>_⊤_</sup> _c_ ( _x_ ) and _y_ _∈_ R <sup>_m_</sup> is a vector of Lagrange multipliers. When _m_ _≪_ _n_, reverse-mode AD is typically more efficient for computing _J_ ( _x_ ) because it propagates derivatives from a small number of outputs. Consequently, using a row coloring strategy is appropriate in this setting to maximize the benefits of reverse-mode AD. However, if a dense column appears in the Jacobian, due to multiple constraints depending on a common variable, a pure row coloring strategy becomes inefficient. Although column coloring using forward-mode AD is an alternative, bicoloring can improve performance by recovering dense columns using forward-mode AD and sparse rows using reverse-mode AD. 1.2.3. Optimal control problems. Discretized optimal control problems [3] often yield Jacobians with structured sparsity patterns, including both dense rows and columns. Consider the following optimal control problem: _x_ ˙ ( _t_ ) = _f_ ( _x_ ( _t_ ) _, u_ ( _t_ ) _, p_ ) _,_ _t ∈_ [0 _,_ 1] _,_ - 1 _g_ ( _x_ ( _t_ ) _, u_ ( _t_ ) _, p_ ) _dt_ = 0 _._ 0 _x_ ( _·_ )min _, u_ ( _·_ ) _, p_ <sup>_C_</sup> <sup>(</sup> <sup>_x_</sup> <sup>(</sup> <sup>_·_</sup> <sup>)</sup> <sup>_, u_</sup> <sup>(</sup> <sup>_·_</sup> <sup>)</sup> <sup>_, p_</sup> <sup>)</sup> subject to ������� where _C_ is a cost function, _x_ ( _t_ ) is the state, _u_ ( _t_ ) is the control, and _p_ represents the parameters that influence the dynamics. In this formulation, _p_ is also treated as a decision variable and optimized jointly with the state and control trajectories; this is particularly useful when _p_ includes physical parameters or the final time _tf_ (after an appropriate time rescaling). Discretizing the interval _t_ = [0 _,_ 1] using a grid _t_ 0 _, t_ 1 _, . . ., tN_ with step sizes _hi_ = _ti_ +1 _−_ _ti_, we define the discrete variables _X_ = ( _x_ 0 _, . . ., xN_ ) and _U_ = ( _u_ 0 _, . . ., uN_ ), where _xi_ _≈_ _x_ ( _ti_ ) and _ui_ _≈_ _u_ ( _ti_ ). Using a Crank–Nicolson (trapezoidal) scheme for the dynamics, we obtain for _i_ = 0 _, . . ., N −_ 1: - _xi_ +1 _−_ _xi −_ <sup>_<u>h</u>_</sup> 2 <sup>_<u>i</u>_</sup> _f_ ( _xi, ui, p_ ) + _f_ ( _xi_ +1 _, ui_ +1 _, p_ ) = 0. Since _p_ appears in every dynamic equation, its derivative contributes to every row of the Jacobian, resulting in a dense column. Similarly, discretizing the integral constraint via the trapezoidal rule gives: - _iN_ =0 _−_ 1 _<u>h</u>_ 2 _<u>i</u>_ - _g_ ( _xi, ui, p_ ) + _g_ ( _xi_ +1 _, ui_ +1 _, p_ )� = 0. This equation aggregates information <sup>_<u>h</u>_</sup> 2 <sup>_<u>i</u>_</sup> _f_ ( _xi, ui, p_ ) + _f_ ( _xi_ +1 _, ui_ +1 _, p_ ) _xi_ +1 _−_ _xi −_ <sup>_<u>h</u>_</sup> 2 <sup>_<u>i</u>_</sup> - _iN_ =0 _−_ 1 _<u>h</u>_ 2 _<u>i</u>_ - _g_ ( _xi, ui, p_ ) + _g_ ( _xi_ +1 _, ui_ +1 _, p_ )� = 0. This equation aggregates information over the entire time horizon, so its derivative with respect to all decision variables produces a dense row in the Jacobian. Note that this behavior is independent of the discretization scheme. Although the Crank–Nicolson scheme is easiest to describe, other schemes exhibit the same behavior. A common strategy to mitigate these dense structures is to augment the state. For instance, instead of treating _p_ as an explicit optimization variable, one can introduce an additional state variable _q_ ( _t_ ) governed by _q_ ˙( _t_ ) = 0, with _q_ (0) = _p_ . Likewise, the integral constraint can be reformulated by introducing an extra state _y_ ( _t_ ) governed by _<u>h</u>_ 2 _<u>i</u>_ - _g_ ( _xi, ui, p_ ) + _g_ ( _xi_ +1 _, ui_ +1 _, p_ ) _<u>hi</u>_ 4 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] _y_ ˙( _t_ ) = _g_ ( _x_ ( _t_ ) _, u_ ( _t_ ) _, p_ ). Instead of adding new variables and constraints through these reformulations, bicoloring enables efficient Jacobian computation without increasing the problem size. 1.3. Related works. The first approaches for efficient computation of sparse Jacobians and Hessians were proposed by Curtis et al. [14] and Powell and Toint [41], respectively. Their connection to graph coloring was discovered by Coleman and Moré [9], Coleman and Moré [10], and McCormick [38], triggering an ambitious research effort to design coloring algorithms and related software [13]. Because the relevant graph coloring problems are NP-hard, most of these algorithms are heuristic in nature. For a detailed account of related literature, see the survey by Gebremedhin et al. [20] and references therein. There are alternative methods for sparse AD which do not rely on colorings [26, Chapter 7], but we will not discuss them here. Given a matrix _A_ _∈_ R <sup>_m×n_</sup> to compress, one seeks the smallest matrix of seeds _U_ _∈{_ 0 _,_ 1 _}_ <sup>_n×c_</sup> (resp. _V_ _∈{_ 0 _,_ 1 _}_ <sup>_m×c_</sup> ) such that the compressed matrix _B_ = _AU_ (resp. _B_ = _V_ <sup>_⊤_</sup> _A_ ) contains all the information needed to recover _A_ . In what follows, this recovery process is also called _decompression_ . For _direct_ decompression, the non-zero entries of _A_ should be directly readable in the compressed matrix _B_ . For decompression by _substitution_, the non-zero entries should be retrievable by solving a triangular system of equations. Choosing the right seeds is equivalent to assigning colors to columns or rows, and then partitioning basis vectors by color. This coloring interpretation requires encoding the matrix _A_ as a graph: two popular representations are the bipartite graph _Gb_ linking rows to columns (for general matrices) and the adjacency graph _Ga_ linking columns with each other (for symmetric matrices). The requirement for injective decompression define the families of colorings that can be used on these graphs (usually more restrictive than the standard distance-1 coloring). Table 1.1 summarizes the coloring models used in derivative computation via direct and substitution-based methods. In all cases, the lower the number of distinct colors, the more efficient the compression. <u>Direct</u> <u>method</u> <u>Substitution</u> <u>method</u> Jacobian, unidirectional _Distance-2_ _coloring_ NA Hessian, unidirectional _Star_ _coloring_ _Acyclic_ _coloring_ Jacobian, bidirectional _Star_ _bicoloring_ _Acyclic_ _bicoloring_ Table 1.1: Overview of coloring problems in derivative computation via direct and substitution methods. Central to our work are the studies focused on symmetric matrices (like Hessians). They give rise to specialized coloring variants: the _star_ _coloring_ and _acyclic_ _coloring_, introduced by Coleman and Moré [10] and Coleman and Cai [8] under slightly different names. We use the terminology of Gebremedhin et al. [20], which underlines the importance of _two-colored_ _substructures_ in star and acyclic colorings of the adjacency graph _Ga_ . In a star coloring (which corresponds to direct decompression), given any pair of colors, the induced subgraph is a _collection_ _of_ _stars_ . In an acyclic coloring (which corresponds to decompression by substitution), it is a _collection_ _of_ _trees_ . These insights were exploited by Gebremedhin et al. [21, 22] to design efficient coloring and decompression routines. Figure 1.3a showcases examples of star and acyclic colorings. A coloring model of particular interest to us is bicoloring, which is used in computations of Jacobians and was suggested independently by Hossain and Steihaug [30] and Coleman and Verma [11]. The core idea is that combining row and column [toc] Revisiting sparse matrix coloring and bicoloring 5 star coloring acyclic coloring C5 C4 adjacency graph C1 bipartite graph bipartite graph adjacency graph C1 C1 ~~C~~ 2 C3 ~~C~~ 4 ~~C~~ 5 ~~C7~~ ~~C6~~ ~~C~~ 2 ~~C~~ 3 star bicoloring acyclic bicoloring R1 ~~R2~~ R3 ~~R4~~ ~~R5~~ R6 C1 ~~C~~ 2 C3 ~~C~~ 4 ~~C~~ 5 ~~C7~~ ~~C6~~ ~~C~~ 2 ~~C~~ 3 C5 C4 (a) Star and acyclic colorings of a symmetric matrix. (b) Star and acyclic bicolorings of a non-symmetric matrix. R1 ~~R2~~ R3 ~~R4~~ ~~R5~~ R6 Fig. 1.3: Example colorings and bicolorings with their graph representations. compression can yield fewer colors overall than either one separately. In this setting, recovery is based on a pair ( _Bc_ = _AU,_ _Br_ = _V_ <sup>_⊤_</sup> _A_ ) of column- and row-compressed matrices rather than a single compressed matrix. The typical objective is to minimize the total number of seeds in ( _U,_ _V_ ). Bicoloring may leave some columns (resp. rows) uncolored if all their non-zeros can already be recovered from the corresponding rows (resp. columns). In such cases, we say that uncolored rows and columns use the _neutral_ _color_ . Examples of bidirectional colorings are displayed on Figure 1.3b. With direct decompression for bidirectional Jacobian computation in mind, Hossain and Steihaug [30] elicit the constraint that every path on four vertices in the bipartite graph _Gb_ should use at least three colors, and deduce a simple greedy algorithm for bicoloring. Coleman and Verma [11] offer a more general treatment which also applies to decompression by substitution, by specifying that every cycle in _Gb_ should use at least three colors. Their algorithm includes a preprocessing step to decide which vertices could be left uncolored, which can be cast as an independent set problem. Gebremedhin et al. [20] compare both approaches and suggests connections with the theoretical framework developed for symmetric matrices. Goyal and Hossain [25] suggest an Integer Linear Programming (ILP) formulation. Juedes and Jones [32] propose a bicoloring algorithm with a guaranteed approximation ratio on the number of colors. Hossain and Steihaug [31] explore a new type of graph encoding which they claim is better suited to bidirectional approaches, but does not exhibit invariance by permutation. Xu and Coleman [46] generalize existing methods to account for other kinds of structure in the Jacobian (like repetition), as well as partial determination. Gaur et al. [19] give a new lower bound on the number of colors necessary for bicoloring and outline an intricate heuristic algorithm. Juedes and Jones [33] extend their previous study of approximation ratios and introduce new algorithms with performance guarantees. Finally, a recent paper by Gaur et al. [18] leverages a new ILP formulation with column generation to obtain good-quality solutions. 6 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] In terms of existing software implementations, `ColPack` [23] stands out because it was designed as a standalone matrix coloring library in C++, encompassing a wide variety of algorithms. That is why we choose it as our point of comparison. To the best of our knowledge, coloring tools are most often part of larger AD frameworks, integrated to enable sparse Jacobians and Hessians. `ColPack` itself interfaces with C/C++ AD toolkits like `ADOL-C` [27, 43], `CppAD` [2] or `ADIC2` [39, 40]. Sparse matrix coloring implementations for other languages include `ADMIT` [12], `ADiMAT` [44] and `MAD` [17] in MATLAB, `SparseDiffTools.jl` [24, 34] in Julia, `SparseHessianFD` [7] in R, `sparsejac` [42] in Python, as well as the domain-specific languages `CasADi` [1] and `JuMP.jl` [16, 37] for mathematical programming. 1.4. Contributions. This paper presents novel bicoloring algorithms, both with direct decompression and decompression via substitution. In contrast to previous approaches, our work builds on existing algorithms for star and acyclic coloring to address the bicoloring problem. Additionally, we propose a _post-processing_ routine for symmetric colorings and bicolorings that aims to neutralize unneeded colors. In this context, we clarify the relationship between the neutral color and the use of two-colored stars and trees during the decompression of star and acyclic colorings. Implementation improvements are also described for star and acyclic coloring, as well as for decompression and vertex ordering. We further introduce the Julia package `SparseMatrixColorings.jl` <sup>1</sup>, which provides implementations of our new methods, along with improved versions of classical techniques for row, column, star, and acyclic colorings, as well as ordering and decompression routines. It was designed as an alternative to `ColPack` [23], written in a high-level programming language [4] with much fewer lines of code but nearly equivalent functionality and comparable speed. 2. Relation between bidirectional colorings and symmetric colorings. Unlike unidirectional colorings, where an entry _Jij_ can only be directly recovered from the compressed row of its row’s color (in row coloring) or the compressed column of its column’s color (in column coloring), bidirectional colorings offer more flexibility by leveraging both colors. This enables more efficient recovery, both directly and through substitution. This flexibility is also present in symmetric colorings, where any entry _Hij_ in the lower triangular part ( _i_ _≥_ _j_ ) can be recovered from its symmetric counterpart _Hji_ in the upper triangular part. The symmetry relation _Hij_ = _Hji_ thus allows leveraging color choices along both the row and column dimensions. Building on this observation, we propose a new bidirectional coloring approach that reformulates the bicoloring problem as a symmetric coloring problem. To achieve this, we construct an _augmented_ _matrix_ _H_, where _J_ is stored in the lower triangular portion and _J_ <sup>_⊤_</sup> in the upper triangular portion. This formulation is given by: (2.1) _H_ := - 0 _J_ <sup>_⊤_</sup> _J_ 0 _._ The adjacency graph _Ga_ of the augmented matrix _H_ is exactly the same as the bipartite graph _Gb_ of the initial matrix _J_ . With this representation, the symmetric colors assigned to the first _n_ columns (or rows) of _H_ determine the column colors of _J_, while those assigned to the last _m_ columns (or rows) of _H_ determine the row colors of _J_ . Recovering _J_ only requires decompressing the lower triangular portion 1 `[https://github.com/gdalle/SparseMatrixColorings.jl](https://github.com/gdalle/SparseMatrixColorings.jl)` [toc] Revisiting sparse matrix coloring and bicoloring 7 of _H_, which is a standard procedure for symmetric matrices where only one triangle needs to be stored. This transformation allows us to extend the well-established symmetric coloring algorithms - such as star and acyclic coloring techniques - along with their associated decompression strategies and complexity properties developed by Gebremedhin et al. [21, 22] to the context of bicoloring. Figures 2.1a and 2.1b illustrate how a symmetric coloring of _H_ translates into a bidirectional coloring of _J_, which exhibits a rectangular sparsity pattern. Note that a representation of adjoint graph in the context of hypergraphs [36] shares similarities with the structure of the augmented matrix (2.1). (a) Symmetric coloring on _H_ . Nonzeros are colored by the color of their columns on the left panel and by the color of their rows on the right panel. (b) Bicoloring on _J_ . Nonzeros are colored according to their column colors in the top panel and according to their row colors in the bottom panel. Fig. 2.1: Link between symmetric coloring and bicoloring To preserve the mapping between the symmetric colors of _H_ (stored as an integer vector `sym_colors` ) and the row and column colors of _J_ (stored as integer vectors `row_colors` and `col_colors` ), we introduce two additional integer vectors: `sym_to_col` and `sym_to_row` . These vectors associate each symmetric color (numbered from `1` to `num_sym_colors` ) with its corresponding column and row colors. If an entry in either `sym_to_col` (or `sym_to_row` ) is `0`, it signifies that the corresponding symmetric color is exclusively assigned to a subset of rows (or columns) in _J_ . Additionally, we require that the row and column colors be consecutively numbered starting from `1` . This contiguous indexing is crucial because each row or column index in the compressed matrices is directly related to a color. Maintaining this mapping simplifies the selection of seeds for AD and streamlines the decompression step. Algorithm 2.1 illustrates the algorithm used to compute the correspondence between the symmetric colors of _H_ and the row and column colors of _J_ . Since our approach relies on symmetric colorings, the decompression routines require access to the compressed symmetric matrix _Bs_ (or its transpose). _Bs_ corresponds to the compression of the columns of _H_, grouped according to symmetric colors. Compressing by rows instead yields _Bs_ <sup>_⊤_</sup> <sup>.</sup> <sup>Thanks</sup> <sup>to</sup> <sup>our</sup> <sup>mapping,</sup> <sup>explicitly</sup> constructing _Bs_ is unnecessary. Each coefficient of _Bs_ can be efficiently retrieved from _Br_ and _Bc_, where _Br_ stores the compressed rows of _J_, grouped by row colors, and _Bc_ stores the compressed columns of _J_, grouped by column colors. The following holds: _Br_ `[sym_to_row[c],` `r]` if 1 _≤_ `r` _≤_ _n_ and `sym_to_row[c]` _̸_ = 0 _,_ (2.2) _Bs_ `[r,c]` =   _̸_ _Bc_ `[r-n,` `sym_to_col[c]]` if 1 _≤_ `r` _−_ _n ≤_ _m_ and `sym_to_col[c]` _̸_ = 0 _,_  `0` otherwise. Bands of zeros in _Bs_ that are not needed during decompression are not explicitly 8 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] Input: _•_ Two integers `m` and `n` corresponding to the number of rows and columns of _J_ . _•_ An integer `num_sym_colors` representing the total number of symmetric colors. _•_ An integer array `sym_colors[1...(n+m)]` specifying a star or acyclic coloring. Output: _•_ `row_colors[1...m]` : renumbered colors for rows. _•_ `col_colors[1...n]` : renumbered colors for columns. _•_ `sym_to_row[1...num_sym_colors]` : maps symmetric colors to row colors. _•_ `sym_to_col[1...num_sym_colors]` : maps symmetric colors to column colors. _•_ `num_row_colors` : number of colors for rows. _•_ `num_col_colors` : number of colors for columns. 1: `sym_to_col` [1. . . `num_sym_colors` ] _←_ 0 2: `col_colors[1...n]` _←_ 0 3: `num_col_colors` _←_ 0 4: for _j_ _←_ 1 _, . . ., n_ do 5: Let _cj_ _←_ `sym_colors[j]` 6: if _cj_ _>_ 0 then 7: if `sym_to_col[` _cj_ `]` `==` 0 then 8: `num_col_colors` _←_ `num_col_colors` `+` `1` 9: `sym_to_col[` _cj_ `]` _←_ `num_col_colors` 10: end if 11: `col_colors[j]` _←_ `sym_to_col[` _cj_ `]` 12: end if 13: end for 14: `sym_to_row[1...num_sym_colors]` _←_ 0 15: `row_colors[1...m]` _←_ 0 16: `num_row_colors` _←_ 0 17: for _i ←_ `n+1,...,n+m` do 18: Let _ci_ _←_ `sym_colors[i]` 19: if _ci_ _>_ 0 then 20: if `sym_to_row[` _ci_ `]` `==` 0 then 21: `num_row_colors` _←_ `num_row_colors` `+` `1` 22: `sym_to_row[` _ci_ `]` _←_ `num_row_colors` 23: end if 24: `row_colors[i-n]` _←_ `sym_to_row[` _ci_ `]` 25: end if 26: end for Algorithm 2.1: Procedure `remap_colors` for mapping symmetric colors to row and column colors. The arrays use 1-based indexing. stored in _Br_ and _Bc_ . They correspond to the structural zero blocks in _H_ . In Equation (2.1), we could have chosen to put _J_ <sup>_⊤_</sup> in the lower triangular portion and _J_ in the upper triangular portion instead. This switch is equally valid, and only requires minor adaptations in our algorithms. It would amount to reverting the order of vertices in the augmented adjacency graph _Ga_ obtained from the bipartite graph _Gb_, listing row vertices first and column vertices next. 3. Post-processing. 3.1. Neutral color in symmetric and bidirectional colorings. We can see in Figures 2.1a and 2.1b that the dark blue color is unnecessary, so the rows and columns currently using it can be left uncolored instead, as illustrated in Figure 1.2. A neutral color indicates that the coefficients of neutralized columns or rows are not needed to recover all non-zeros. This is materialized by a blank square or triangle in our visualizations. We developed a post-processing algorithm to reduce the number of colors by replacing some of them with a neutral color after applying symmetric colorings, [toc] Revisiting sparse matrix coloring and bicoloring 9 thereby also reducing the number of colors in our bicolorings. Thanks to symmetry, each off-diagonal entry can be recovered from either its row or its column, which are associated with different indices. In previous symmetric coloring approaches, every diagonal coefficient was assumed to be nonzero, making each color essential for diagonal retrieval and leaving no room for neutral colors. In contrast, for our bicoloring approach, all diagonal elements of _H_ are zero, making post-processing beneficial. Note that our approach is not specific to the 2 _×_ 2 block structure of _H_ used for bicoloring. It can be applied to any symmetric matrix with at least some zeros on its diagonal and that has been colored using star or acyclic coloring. After our post-processing, the non-neutral (i.e. colored) row and column vertices constitute a _vertex_ _cover_ of the corresponding graph ( _Ga_ or _Gb_ ). Indeed, every nonzero entry (edge in the graph) is incident to at least one colored vertex. 3.2. Relation between neutral color and two-colored structures. In graph theory, star and acyclic colorings are specialized forms of vertex colorings that impose additional constraints to prevent certain substructures within the graph. A star coloring is a proper vertex coloring where no path on four vertices uses two colors, meaning any path on four vertices uses at least three distinct colors. This restriction ensures that the subgraph induced by any two color structures forms a disjoint union of star graphs, thereby eliminating bicolored four-vertex paths. An acyclic coloring is a proper vertex coloring such that every cycle in the graph is colored with at least three colors, ensuring that no two-colored cycles exist. In other words, the subgraph induced by any two color structures is a forest, thereby eliminating bicolored cycles. Figure 3.1 illustrates the variants of two-colored structures encountered in star and acylic colorings. 2 4 1 2 3 4 5 6 7 3 1 1 4 2 3 ○4 ○3 ○2 ○1          ○4 ○4 ○4 ○1 ○2 ○3    ○2 ○3 ○1 ○4 ○5 ○1 ○6 ○7 ○2 ○2 ○3 ○3 (a) Trivial star/tree (b) Normal star (c) Normal tree Fig. 3.1: Variants of two-colored structures with example matrices. To determine if a color can be discarded, we need to identify cases where the color is not required during the decompression phase in star and acyclic colorings, which rely on two-colored structures. The first prerequisite for neutralizing a color in symmetric colorings is that it is not needed to recover diagonal coefficients. In the context of star coloring, only the color of the hubs of the stars is needed during decompression. The color of the spokes is not used (see the routine _DirectRecover2_ in Gebremedhin et al. [22]). To illustrate this, consider an adjacency matrix _J_ with one row and three 10 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] columns. The associated augmented matrix _H_ is represented on Figure 3.1b): Here, the columns colored blue (spokes) are not used; only the column colored red (hub) is needed. Consequently, any color that does not appear in the hubs of any two-colored stars can safely be replaced by the neutral color. In the context of acyclic coloring, only the color of the leaves in trees is not needed during decompression (see the routine _IndirectRecover_ in Gebremedhin et al. [22]). However, for two-colored trees that are neither trivial nor standard two-colored stars (trees with a depth of at least 2), both colors must be retained as they correspond to the root and internal nodes (see the graph in Figure 3.1c). Therefore, the colors that can be neutralized in trees are those found in edges and stars (trees with a depth of 1). The main challenge comes from edges, which are simplified forms of two-colored stars and trees that can be found in both star and acyclic colorings. In these cases, the color of either vertex can be used for decompression. For that reason, we suggest first processing all two-colored stars and trees with at least three vertices. Then, at the end of the procedure, we iterate over the remaining edges, leveraging our knowledge of nontrivial stars and trees. For each edge, if either of its two vertices is already (a) a hub of a normal two-colored star or (b) is simply a vertex in a normal two-colored tree, we cannot give it the neutral color. Thus, we choose to use that vertex for decompression of the current edge. Therein lies the benefit of processing individual edges at the end: if one color is already indispensable, we pick it for the hub, instead of making the other color indispensable too when it is not needed. On the other hand, if both colors can still be neutralized in the edge, we must arbitrarily neutralize one and then ensure that decompression uses the color of the other vertex. It may require updating who the hub is in these trivial two-colored structures. For example, consider the following anti-diagonal matrix of Figure 3.1a. We can remove either the blue or red color to compute all non-zeros. Algorithm 3.1 summarizes the post-processing algorithm for star and acyclic colorings. Note that it can be simplified if we only use it for bicoloring, because _H_ always has a diagonal of zeros, as well as in star coloring, because the set of normal two-colored trees _T_ is always empty. Because an arbitrary choice may be necessary to neutralize one color in trivial two-colored structures, the total number of neutralized colors may vary. In the context of bicoloring, this choice can be made to reduce the number of colors in either the column partition or the row partition of a Jacobian. Depending on the shape of the Jacobian, as well as the cost of forward and reverse AD, one option may be more advantageous than the other. 3.3. Post-processing without color elimination. We recall that the postprocessing aims to minimize the total number of colors, rather than maximizing the assignments of the neutral color. In some cases, the color assignments of rows and columns could be replaced with the neutral color without reducing the total number of distinct colors. This change affects only the seeds and does not benefit most AD tools. Tools like `Tapenade` [28] utilize activity analysis to identify active variables and skip computations on inactive ones. While this approach may optimize the process, further research is needed to determine if practical performance gains can be achieved. Additionally, this optimization could require different code being used to compute _Ju_ and _J_ <sup>_⊤_</sup> _v_, depending on the seeds. 4. A new kind of coloring. In the symmetric setting, replacing some colors with the neutral color 0 means that the end result is no longer a standard star or acyclic coloring. We shed light on the resulting object in the case of star coloring only, [toc] Revisiting sparse matrix coloring and bicoloring 11 Input: _•_ An integer `p` corresponding to the dimension of a symmetric matrix _H_ . _•_ An integer `num_sym_colors` representing the total number of symmetric colors. _•_ An integer array `sym_colors[1...p]` specifying a star or acyclic coloring. _•_ An integer array `offsets[1...p]` used as a workspace. _•_ A boolean vector `used[1...num_sym_colors]` : colors that can be neutralized. _•_ A set _T_ of normal two-colored trees. _•_ A set _S_ of normal two-colored stars. _•_ A set _E_ of trivial two-colored structures. Output: _•_ The integer vector `sym_colors[1...p]` updated. 1: `used[1...num_sym_colors]` _←_ `false` 2: for _k_ _←_ 1 _, . . ., p_ do 3: if _Hk,k̸_ = 0 then 4: `used[sym_colors[k]]` `=` `true` 5: end if 6: end for 7: for each normal two-colored tree T in _T_ do 8: Let _i_ and _j_ be the indices of two vertices connected by an edge in T 9: `used[sym_colors[i]]` `=` `true` 10: `used[sym_colors[j]]` `=` `true` 11: end for 12: for each normal two-colored star S in _S_ do 13: Let _h_ be the index of the hub vertex in S 14: `used[sym_colors[h]]` `=` `true` 15: end for 16: for each trivial two-colored structure E in _E_ do 17: Let _i_ and _j_ be the indices of the two vertices of the edge E 18: if `used[sym_colors[i]]` or `used[sym_colors[j]]` then 19: Choose the hub _h_ as _i_ or _j_ such that its color is used 20: else 21: Choose the hub _h_ arbitrary between _i_ and _j_ 22: `used[sym_colors[h]]` `=` `true` 23: end if 24: end for 25: `num_neutral_colors` _←_ 0 26: for `c` _←_ `1` to `num_sym_colors` do 27: if ( not `color_used[c]` ) then 28: `num_neutral_colors` _←_ `num_neutral_colors` `+` `1` 29: else 30: `offsets[c]` _←_ `num_neutral_colors` 31: end if 32: end for 33: for `i` _←_ `1` to `p` do 34: `c` _←_ `sym_colors[i]` 35: if ( not `used[c]` ) then 36: `sym_color[i]` _←_ 0 37: else 38: `sym_color[i]` _←_ `sym_color[i]` _−_ `offsets[c]` 39: end if 40: end for Algorithm 3.1: Procedure `post_processing` for discarding colors after star and acyclic colorings. The arrays use 1-based indexing. leaving acyclic coloring for future work. 4.1. Partition perspective. First, we recall the goal of coloring a symmetric matrix _A_ with direct decompression: obtaining a compressed representation from which every non-zero coefficient can be read directly. Following Gebremedhin et al. 12 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] [20, Definition 4.2], a _symmetrically_ _orthogonal_ _partition_ of the columns of _A_ is such that for every _Aij̸_ = 0, either (1) _Aj_ is the only column in its group with a non-zero entry in row _i_, or (2) _Ai_ is the only column in its group with a non-zero entry in row _j_ . Coleman and Moré [10] prove that every star coloring of the adjacency graph of _A_ induces a symmetrically orthogonal partition of the columns of _A_ . On the other hand, our post-processing method modifies the star coloring to induce a _neutralized_ _symmetrically_ _orthogonal_ _partition_ : it is such that for every _Aij̸_ = 0, either (1) _Aj_ has a non-neutral color and is the only column in its group with a non-zero entry in row _i_, or (2) _Ai_ has a non-neutral color and is the only column in its group with a non-zero entry in row _j_ . We now give a graph characterization of this object in the special case where all diagonal coefficients of _A_ are zero, which applies to the augmented matrix of (2.1). The usual star coloring corresponds to the opposite case where all diagonal coefficients are non-zero, which means the neutral color cannot be used. Intermediate cases where only some coefficients are non-zero may also be described, but the ensuing definitions are less crisp because the adjacency graph is not sufficient to distinguish between zero and non-zero diagonal entries (unless self-loops are considered). 4.2. Graph perspective. Let _A_ be a symmetric _n × n_ matrix whose diagonal entries are all zero. Let _ϕ_ : _{_ 1 _, . . ., n} →{_ 1 _, . . ., n}_ be a mapping from the columns of _A_ to integer colors. Any such mapping defines a partition _Pϕ_ of the columns of _A_, by gathering columns with the same color _c_ inside a single group _Pϕ_ [ _c_ ] := _{k_ _∈_ _{_ 1 _, . . ., n}_ : _ϕ_ ( _k_ ) = _c}_ . As before, 0 denotes a neutral color, which is not used for recovery of the matrix. Let _Ga_ = ( _V, E_ ) denote the adjacency graph of _A_, with vertex set _V_ = _{_ 1 _, . . ., n}_ and edge set _E_ = _{_ ( _i, j_ ) : _Aij̸_ = 0 _}_ . _Definition._ We say that _ϕ_ is a _no-zig-zag_ _coloring_ of the adjacency graph _Ga_ if the following conditions are all met: 1. Every edge is incident on at least one colored vertex: if ( _i, j_ ) _∈E_, then _ϕ_ ( _i_ ) _>_ 0 or _ϕ_ ( _j_ ) _>_ 0. 2. Neutral-colored vertices have distinctly-colored neighbors: if _j_ and _q_ are adjacent to the same _i_ such that _ϕ_ ( _i_ ) = 0, then _ϕ_ ( _j_ ) _̸_ = _ϕ_ ( _q_ ). 3. There is no color-alternated (zig-zagging) path on four vertices: for any path ( _q, i, j, p_ ) in _Ga_, either _ϕ_ ( _q_ ) _̸_ = _ϕ_ ( _j_ ) or _ϕ_ ( _i_ ) _̸_ = _ϕ_ ( _p_ ), so that we cannot have a succession of colors of the form ( _c_ 1 _, c_ 2 _, c_ 1 _, c_ 2). Note that this definition does not require _ϕ_ to be a coloring of _Ga_ in the usual sense: adjacent vertices are allowed to share the same non-neutral color _c_ _>_ 0. Therefore, no-zig-zag coloring is a relaxation of star coloring, as introduced by Coleman and Moré [10]. It is also related to star bicoloring, as introduced by Coleman and Verma [11]. _Theorem._ The mapping _ϕ_ is a no-zig-zag coloring of _Ga_ if and only if the partition _Pϕ_ is a neutralized symmetrically orthogonal partition of the columns of _A_ . Before the formal proof, we give an intuitive way to obtain it. Given the matrix _A_ below, we check which two-colored partitions allow recovery of _Aij_ (up to color switch). The results show that the only forbidden coloring pattern for path ( _q, i, j, p_ ) is the zig-zag. _·_ _Aqi_ _·_ _·_ _Aiq_ _·_ _Aij_ _·_ _·_ _Aji_ _·_ _Ajp_ _·_ _·_ _Apj_ _·_ _<u>q</u>_ _<u>i</u>_ _<u>j</u>_ _<u>p</u>_ <u>recoverable</u> _<u>Aij</u>_ _c_ 1 _c_ 2 _c_ 1 _c_ 2 no _c_ 1 _c_ 1 _c_ 2 _c_ 2 yes (in _c_ 1 or _c_ 2) _c_ 1 _c_ 2 _c_ 2 _c_ 1 yes (in _c_ 2) _c_ 1 _c_ 1 _c_ 1 _c_ 2 yes (in _c_ 1) _<u>c</u>_ <u>1</u> _<u>c</u>_ <u>1</u> _<u>c</u>_ <u>2</u> _<u>c</u>_ <u>1</u> <u>yes</u> <u>(in</u> _<u>c</u>_ <u>2)</u>     _A_ =     [toc] Revisiting sparse matrix coloring and bicoloring 13 _Proof._ We tackle the two implications sequentially. = _⇒_ Let _ϕ_ define a no-zig-zag coloring of _Ga_ . If the partition _Pϕ_ is not a neutralized symmetrically orthogonal for _A_, there exists ( _i, j_ ) such that _Aij̸_ = 0 cannot be recovered from _i_ nor from _j_ . This means we are in one of the following situations (the conditions refer to those defining the no-zig-zag coloring): _•_ _ϕ_ ( _i_ ) = 0. By condition 1, _ϕ_ ( _j_ ) _>_ 0. Since _Aij_ cannot be recovered from _j_, there exists a column _q_ with _Aiq̸_ = 0 such that _ϕ_ ( _q_ ) = _ϕ_ ( _j_ ). This violates condition 2. _•_ _ϕ_ ( _j_ ) = 0. By condition 1, _ϕ_ ( _i_ ) _>_ 0. Since _Aij_ cannot be recovered from _i_, there exists a column _p_ with _Ajp̸_ = 0 such that _ϕ_ ( _p_ ) = _ϕ_ ( _i_ ). This violates condition 2. _•_ _ϕ_ ( _i_ ) _>_ 0 and _ϕ_ ( _j_ ) _>_ 0. Since _Aij_ cannot be recovered from _i_ nor from _j_, there exist _q_ and _p_ such that _Aiq̸_ = 0, _Ajp̸_ = 0, _ϕ_ ( _i_ ) = _ϕ_ ( _p_ ) and _ϕ_ ( _j_ ) = _ϕ_ ( _q_ ). But then the path ( _q, i, j, p_ ) is color-alternated, which violates condition 3. _⇐_ = Let _Pϕ_ be a neutralized symmetrically orthogonal partition for _A_ . We now check the conditions of the no-zig-zag coloring one by one: 1. For _Aij̸_ = 0 to be recoverable, either _ϕ_ ( _i_ ) _>_ 0 or _ϕ_ ( _j_ ) _>_ 0 must hold. So the edge ( _i, j_ ) _∈E_ is incident on at least one colored vertex. 2. If _ϕ_ ( _i_ ) = 0 and _i_ has two neighbors _j_ and _q_, then _Aij_ can only be recovered from _j_ and _Aiq_ from _q_ . This implies that _ϕ_ ( _j_ ) _̸_ = _ϕ_ ( _q_ ). 3. Let ( _q, i, j, p_ ) be a path in _Ga_ . _•_ Assume _ϕ_ ( _i_ ) = 0 (resp. _ϕ_ ( _j_ ) = 0). Then, condition 2 imposes distinctly colored neighbors for _i_ (resp. _j_ ). This brings the total number of colors to at least 3 and precludes a color-alternated path. _•_ Now assume _ϕ_ ( _i_ ) _>_ 0 and _ϕ_ ( _j_ ) _>_ 0. Since _Aij_ is recoverable, this means that either _ϕ_ ( _p_ ) _̸_ = _ϕ_ ( _i_ ) or _ϕ_ ( _q_ ) _̸_ = _ϕ_ ( _j_ ). Thus, the path cannot be color-alternated either. _In_ _the_ _rest_ _of_ _the_ _paper,_ _even_ _when_ _our_ _star_ _and_ _acyclic_ _coloring_ _algorithms_ _are_ _enhanced_ _with_ _post-processing,_ _we_ _still_ _refer_ _to_ _them_ _under_ _the_ _same_ _name._ This makes the comparison with previous versions more concise, in particular for benchmark tables. The reader should keep in mind that the actual object we obtain is a relaxation of the usual symmetric coloring concepts. 5. Software implementation. `SparseMatrixColorings.jl` (or `SMC` for short) is an open source library containing our new coloring algorithms, as well as some standard ones. It can be seen as a modernization of `ColPack` [23], written in a highlevel language that facilitates applications. The implementation is based partly on a series of papers by the `ColPack` authors [20–23], but includes new algorithmic ideas. In particular, for bidirectional problems, `ColPack` only supports star bicoloring, while `SMC` includes our new acyclic bicoloring. As the benchmarks will demonstrate, this can lead to a smaller number of colors. Furthermore, we fixed several bugs in `ColPack`, developed a C interface, and created a Julia wrapper `ColPack.jl` <sup>2</sup> . The resulting fork <sup>3</sup> of `ColPack` is made publicly available on GitHub. 5.1. Features and design. Like `ColPack`, our `SMC` package offers a variety of coloring and decompression options. It can compute either column, row or bidirectional 2 `[https://github.com/Exanauts/ColPack.jl](https://github.com/Exanauts/ColPack.jl)` 3 `[https://github.com/amontoison/ColPack](https://github.com/amontoison/ColPack)` 14 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] colorings, for symmetric or non-symmetric matrices, with direct or indirect decompression. This translates into five different core algorithms: partial distance-2 coloring, star and acyclic coloring, and star and acyclic bicoloring. All of these algorithms employ greedy procedures that color vertices one after another. Since the order in which vertices are considered impacts the number of colors used, we allow users to select an ordering criterion: natural, random, largest first, dynamic largest first, smallest last, or incidence degree [23]. For each variant of the coloring problem, we only offer the most suitable model and leave alternative approaches aside. As an example, we provide a partial distance-2 coloring for bipartite graphs, but not distance-1 coloring on intersection graphs (which would be computationally more expensive [20]). Thanks to our Julia implementation, `SMC` enjoys the benefits of just-in-time compilation and multiple dispatch [4]. Fast code is generated for a variety of input formats and number types, without needing to anticipate each one. At the same time, the use of a high-level language enables remarkable conciseness: according to `cloc` <sup>4</sup>, the entire package requires around 5 000 lines of Julia code, against nearly 30 000 lines of C `++` for `ColPack`, with comparable functionalities. 5.2. Fast and flexible decompression. We took great care to optimize the performance of `SMC`, with a particular focus on decompression. Indeed, while coloring is usually performed just once, and then amortized over every subsequent Jacobian or Hessian computation, decompression is an integral part of derivative computations and often happens inside hot loops. Thus, the coloring step in `SMC` includes preallocation of necessary memory and pre-computation of relevant information, to make decompression as efficient as possible. While `SMC` allows decompression into arbitrary matrices, it is most efficient when presented with sparse storage. Typical formats for sparse matrices include Compressed Sparse Column (CSC) or Compressed Sparse Row (CSR). The CSC format, which Julia considers the default, comprises three arrays: _•_ `nzval`, containing the nonzero values of the matrix, concatenated column-wise; _•_ `rowval`, containing the corresponding row indices, sorted in ascending order; _•_ `colptr`, an integer array of length _n_ + 1 such that, for each column `j`, its nonzero entries appear in `nzval` and `rowval` at positions `colptr[j]` through `colptr[j+1]-1` . Accessing a single coefficient `A[i,j]` in a CSC matrix `A` is expensive. It requires a binary search to find `k` on the sorted slice `colptr[j]:colptr[j+1]-1` such that `rowval[k]` `=` `i`, after which the requested value is read from or written to at `nzval[k]` . Thus, a naive unidirectional decompression `A[i,j]` `=` `B[i,color[j]]` will be slower than it needs to be. That is why we precompute a vector of compressed indices such that `nzval[k]` `=` `B[compressed_indices[k]]`, where the matrix `B` is indexed linearly columnwise. With this preliminary step out of the way, decompression turns into a simple loop over all `k` `in` `1:nnz(A)` without binary search. The computation of `compressed_indices` is a one-time cost and is quickly amortized when we need to perform multiple decompressions, as is the case in non-linear optimization methods that require many Jacobians and Hessians. It also allows decompression on SIMD architectures such as GPUs. Anticipating cases where _B_ itself might be too expensive to store, we also provide utilities for decompressing a single color at a time when it is feasible (which amounts to _B_ having a single column or row). Similarly, in the case of symmetric matrices, we offer decompression inside a single triangle (lower or upper), thus skipping duplicate 4 `[https://github.com/AlDanial/cloc](https://github.com/AlDanial/cloc)` [toc] Revisiting sparse matrix coloring and bicoloring 15 work. As noted earlier, decompression into a triangle for star and acyclic colorings is a crucial ingredient of our bidirectional decompression using the augmented matrix. 5.3. Performance considerations. In general, we found that the previously available pseudocode did not include all the necessary subtleties for efficient implementation of coloring and decompression algorithms. Therefore, we have listed some of these missing implementation details, as well as improvements we discovered, in Appendix A. Notable performance optimizations include: _•_ Complete avoidance of hash tables for edge index management; _•_ Efficient reconstruction of 2-colored tree structures after acyclic coloring; _•_ Low-memory buckets for the dynamic degree-based orderings. 5.4. Integration with other tools. `SMC` integrates seamlessly with two other Julia packages: `SparseConnectivityTracer.jl` <sup>5</sup> and `DifferentiationInterface.jl` <sup>6</sup> . The former provides utilities for sparsity pattern detection, a crucial step in the coloring process of Jacobians and Hessians, while the latter offers standardized access to various AD backends for computing JVPs, VJPs and HVPs. Together, these packages form a cohesive ecosystem for sparse AD in Julia [29]. With the upcoming release of Julia version 1.12, it will become possible to distribute small binaries and shared libraries of Julia packages. Then, we plan to create a C interface for `SMC`, aiming to improve its interoperability with other established AD systems such as `ADOL-C` [27] and `CasADi` [1]. 6. Numerical experiments. We performed extensive numerical experiments comparing `SMC` with `ColPack` (or `CP` for short), both in terms of number of colors and in terms of runtime. Our test instances come from previous works: we reuse the nonsymmetric matrices from Gebremedhin et al. [23, Tables VI and VII], and the symmetric matrices from Gebremedhin et al. [20, Table 4.2] <sup>7</sup> . For the experiments below, we also include the Linear Programming and Harwell-Boeing matrices studied by Coleman and Verma [11, Tables 5.1 and 5.3] <sup>8</sup> . Statistics on the sizes of all the matrices used in our experiments are provided in Table 6.1. We only present our main bicoloring results in this section, the rest of the tables can be found in Appendix B. Table 6.2 compares the variants of bicoloring in `ColPack` and `SMC` in terms of the number of colors returned. It also reports the number of colors obtained by Coleman and Verma [11] with their bicoloring algorithm, referred to as `CV`, which we did not run ourselves. The variant of star bicoloring chosen for `ColPack` is `ImplicitCoveringStarBicoloring`, which was named as the best overall in Gebremedhin et al. [23]. For the star and acyclic bicoloring in `SMC`, the post-processing procedure is used. The boldfaced value indicates the lowest number of colors in each row. As we can see, our acyclic bicoloring implementation (which enables decompression by substitution and was not available in `ColPack` ) can give rise to fewer colors than implementations of star bicoloring in `ColPack` and `SMC` . Note however that these results are dependent on the chosen ordering: more details are given in Appendix B. On most instances, the approach of Coleman and Verma [11] was found to yield fewer colors than `SMC`, yet their method has other drawbacks. For instance, it relies on partial 5 `[https://github.com/adrhill/SparseConnectivityTracer.jl](https://github.com/adrhill/SparseConnectivityTracer.jl)` 6 `[https://github.com/JuliaDiff/DifferentiationInterface.jl](https://github.com/JuliaDiff/DifferentiationInterface.jl)` 7except `mrng1` and `mrng2`, which we did not find in the `SuiteSparse` collection 8except `boeing1` and `boeing2`, which we did not find in the `SuiteSparse` collection 16 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] group name sym rows cols nnz LPnetlib lp_cre_a false 3516 7248 18168 LPnetlib lp_ken_11 false 14694 21349 49058 LPnetlib lp_ken_13 false 28632 42659 97246 LPnetlib lp_maros_r7 false 3136 9408 144848 LPnetlib lp_cre_d false 8926 73948 246614 LPnetlib lp_ken_18 false 105127 154699 358171 Bai af23560 false 23560 23560 484256 Shen e40r0100 false 17281 17281 553562 vanHeukelum cage11 false 39082 39082 559722 vanHeukelum cage12 false 130228 130228 2032536 LPnetlib lp_standata false 359 1274 3230 LPnetlib lp_scagr25 false 471 671 1725 LPnetlib lp_scagr7 false 129 185 465 LPnetlib lp_stair false 356 614 4003 LPnetlib lp_blend false 74 114 522 LPnetlib lp_vtp_base false 198 346 1051 LPnetlib lp_agg false 488 615 2862 LPnetlib lp_agg2 false 516 758 4740 LPnetlib lp_agg3 false 516 758 4756 LPnetlib lp_bore3d false 233 334 1448 LPnetlib lp_israel false 174 316 2443 LPnetlib lp_tuff false 333 628 4561 LPnetlib lp_adlittle false 56 138 424 HB watt_2 false 1856 1856 11550 HB can_256 true 256 256 2916 HB can_268 true 268 268 3082 HB can_292 true 292 292 2540 HB can_634 true 634 634 7228 HB can_715 true 715 715 6665 HB can_1054 true 1054 1054 12196 HB can_1072 true 1072 1072 12444 HB impcol_c false 137 137 411 HB impcol_d false 425 425 1339 HB impcol_e false 225 225 1308 HB west0067 false 67 67 294 HB west0381 false 381 381 2157 HB west0497 false 497 497 1727 HB gent113 false 113 113 655 HB arc130 false 130 130 1282 DIMACS10 598a true 110971 110971 1483868 DIMACS10 144 true 144649 144649 2148786 DIMACS10 m14b true 214765 214765 3358036 DIMACS10 auto true 448695 448695 6629222 Table 6.1: Structure and dimensions of the test matrices. column- and row-intersection graphs (built from a partition of the matrix _A_ into two sides), which can be denser than the original bipartite graph we use. 7. Conclusion. We presented new star and acyclic bicoloring algorithms for bidirectional compression-based computation of sparse Jacobian matrices. They allow the combined use of the forward and reverse modes of AD. We also presented accompanying efficient decompression procedures. Our bicoloring and decompression algorithms leverage the technology previously developed for sparse symmetric matrix (Hessian) computation. Our implementations are delivered via the Julia package `SparseMatrixColorings.jl` . This library also includes implementations of coloring and vertex ordering techniques for unidirectional computation of Jacobians (partial distance-2 coloring) and computation of Hessians (star and acyclic coloring). We showed [toc] Revisiting sparse matrix coloring and bicoloring 17 direct substitution name CP SMC CV SMC CV lp_cre_a 18 16 12 lp_ken_11 6 5 4 lp_ken_13 5 4 4 lp_maros_r7 73 72 72 lp_cre_d 17 15 13 lp_ken_18 6 5 4 af23560 44 32 45 e40r0100 88 87 87 cage11 82 81 79 cage12 97 96 93 lp_standata 11 10 9 8 7 lp_scagr25 10 9 8 5 5 lp_scagr7 10 9 8 5 5 lp_stair 39 38 36 35 29 lp_blend 18 17 16 14 14 lp_vtp_base 14 13 12 9 10 lp_agg 44 43 19 38 13 lp_agg2 44 43 26 38 21 lp_agg3 44 43 27 39 21 lp_bore3d 29 28 28 25 24 lp_israel 137 136 61 107 49 lp_tuff 27 25 21 26 16 lp_adlittle 12 11 11 11 10 watt_2 66 65 20 11 12 can_256 84 83 32 27 23 can_268 39 38 18 26 12 can_292 37 36 17 36 17 can_634 32 31 28 33 21 can_715 106 105 22 18 18 can_1054 37 36 31 25 23 can_1072 37 36 32 25 24 impcol_c 12 11 6 6 4 impcol_d 12 12 6 6 5 impcol_e 33 32 21 24 14 west0067 15 14 9 8 7 west0381 75 74 12 73 9 west0497 56 55 22 18 19 gent113 32 31 19 30 13 arc130 125 124 25 125 23 Table 6.2: Number of colors for bidirectional coloring with natural order, by decompression mode and by package. that `SMC` exhibits comparable performance with `ColPack` while offering additional features and reduced code complexity. We conclude by pointing out a few directions for future work. _•_ As observed in our experiments, the number of colors obtained with our new bicoloring technique still compares unfavorably to the algorithm of Coleman and Verma [11]. Understanding the cause of the difference in performance between the two approaches is an important challenge for further research. _•_ After the completion of the post-processing step (described in Section 3.1) that neutralizes unneeded colors, the rows and columns of the Jacobian that remain with non-neutral (actual) colors define a vertex cover in the bipartite graph view of the Jacobian. The characterization of this vertex cover in graph-theoretic terms is a worthy subject to investigate in future work. 18 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] _•_ The augmented symmetric matrix for a non-symmetric matrix that we relied on for formulating our star and acyclic bicoloring is known in the literature as the adjoint graph representation of a hypergraph. It is worthwhile to explore this connection for studying hypergraph coloring problems. _•_ Our array-based implementation of the recovery routines associated with star and acyclic bicoloring naturally lends itself for parallelization within a SIMD framework. It will be interesting to exploit this to devise efficient GPU implementations. Acknowledgements. Both first authors contributed equally. We acknowledge the ideas and feedback contributed by Paul Hovland during the inception of this paper. We are grateful to Adrian Hill for his implementation of coloring visualization, and for his key role in shaping the sparse AD ecosystem in Julia through joint development efforts. We sincerely thank Jean-Baptiste Caillau for his assistance in describing the applications in optimal control. REFERENCES [1] J. A. E. Andersson, J. Gillis, G. Horn, J. B. Rawlings, and M. Diehl. CasADi: A software framework for nonlinear optimization and optimal control. _Mathematical_ _Programming_ _Com-_ _putation_, 11(1):1–36, Mar. 2019. ISSN 1867-2957. DOI: [10.1007/s12532-018-0139-4.](http://dx.doi.org/10.1007/s12532-018-0139-4) URL [https://doi.org/10.1007/s12532-018-0139-4.](https://doi.org/10.1007/s12532-018-0139-4) [2] B. M. Bell. CppAD: A package for C++ algorithmic differentiation. _Computational Infrastructure_ _for_ _Operations_ _Research_, 57(10):3, 2012. [3] J. T. Betts. _Practical_ _Methods_ _for_ _Optimal_ _Control_ _Using_ _Nonlinear_ _Programming,_ _Third_ _Edition_ . SIAM, July 2020. ISBN 978-1-61197-619-9. [4] J. Bezanson, A. Edelman, S. Karpinski, and V. B. Shah. Julia: A Fresh Approach to Numer ical Computing. _SIAM_ _Review_, 59(1):65–98, Jan. 2017. ISSN 0036-1445, 1095-7200. DOI: [10.1137/141000671.](http://dx.doi.org/10.1137/141000671) URL [https://epubs.siam.org/doi/10.1137/141000671.](https://epubs.siam.org/doi/10.1137/141000671) [5] Å. Björck. _Numerical_ _Methods_ _for_ _Least_ _Squares_ _Problems,_ _Second_ _Edition_ . SIAM, July 2024. ISBN 978-1-61197-795-0. [6] M. Blondel and V. Roulet. The Elements of Differentiable Programming, July 2024. URL [http://arxiv.org/abs/2403.14606.](http://arxiv.org/abs/2403.14606) [7] M. Braun. sparseHessianFD: An R Package for Estimating Sparse Hessian Matrices. _Journal_ _of_ _Statistical_ _Software_, 82(10), 2017. ISSN 1548-7660. DOI: [10.18637/jss.v082.i10.](http://dx.doi.org/10.18637/jss.v082.i10) URL [http://www.jstatsoft.org/v82/i10/.](http://www.jstatsoft.org/v82/i10/) [8] T. F. Coleman and J.-Y. Cai. The Cyclic Coloring Problem and Estimation of Sparse Hessian Matrices. _SIAM_ _Journal_ _on_ _Algebraic_ _Discrete_ _Methods_, 7(2):221–235, Apr. 1986. ISSN 0196-5212. DOI: [10.1137/0607026.](http://dx.doi.org/10.1137/0607026) URL [https://epubs.siam.org/doi/abs/10.1137/0607026.](https://epubs.siam.org/doi/abs/10.1137/0607026) [9] T. F. Coleman and J. J. Moré. Estimation of Sparse Jacobian Matrices and Graph Coloring Problems. _SIAM_ _Journal_ _on_ _Numerical_ _Analysis_, 20(1):187–209, Feb. 1983. ISSN 0036-1429. DOI: [10.1137/0720013.](http://dx.doi.org/10.1137/0720013) URL [https://epubs.siam.org/doi/abs/10.1137/0720013.](https://epubs.siam.org/doi/abs/10.1137/0720013) [10] T. F. Coleman and J. J. Moré. Estimation of sparse hessian matrices and graph coloring problems. _Mathematical_ _Programming_, 28(3):243–270, Oct. 1984. ISSN 1436-4646. DOI: [10.1007/BF02612334.](http://dx.doi.org/10.1007/BF02612334) URL [https://doi.org/10.1007/BF02612334.](https://doi.org/10.1007/BF02612334) [11] T. F. Coleman and A. Verma. The Efficient Computation of Sparse Jacobian Matrices Using Automatic Differentiation. _SIAM_ _Journal_ _on_ _Scientific_ _Computing_, 19(4):1210–1233, Jan. 1998. ISSN 1064-8275. DOI: [10.1137/S1064827595295349.](http://dx.doi.org/10.1137/S1064827595295349) URL [https://epubs.siam.org/doi/abs/10.](https://epubs.siam.org/doi/abs/10.1137/S1064827595295349) [1137/S1064827595295349.](https://epubs.siam.org/doi/abs/10.1137/S1064827595295349) [12] T. F. Coleman and A. Verma. ADMIT-1: Automatic differentiation and MATLAB interface toolbox. _ACM_ _Trans._ _Math._ _Softw._, 26(1):150–175, Mar. 2000. ISSN 0098-3500. DOI: [10.1145/347837.347879.](http://dx.doi.org/10.1145/347837.347879) URL [https://dl.acm.org/doi/10.1145/347837.347879.](https://dl.acm.org/doi/10.1145/347837.347879) [13] T. F. Coleman, B. S. Garbow, and J. J. More. Software for estimating sparse Jacobian matrices. _ACM_ _Transactions_ _on_ _Mathematical_ _Software_, 10(3):329–345, Aug. 1984. ISSN 0098-3500. DOI: [10.1145/1271.1610.](http://dx.doi.org/10.1145/1271.1610) URL [https://dl.acm.org/doi/10.1145/1271.1610.](https://dl.acm.org/doi/10.1145/1271.1610) [14] A. R. Curtis, M. J. D. Powell, and J. K. Reid. On the Estimation of Sparse Jacobian Matrices. _IMA_ _Journal_ _of_ _Applied_ _Mathematics_, 13(1):117–119, Feb. 1974. ISSN 0272-4960. DOI: [10.1093/imamat/13.1.117.](http://dx.doi.org/10.1093/imamat/13.1.117) URL [https://doi.org/10.1093/imamat/13.1.117.](https://doi.org/10.1093/imamat/13.1.117) [toc] Revisiting sparse matrix coloring and bicoloring 19 [15] T. A. Davis and Y. Hu. The university of Florida sparse matrix collection. _ACM_ _Trans._ _Math._ _Softw._, 38(1):1:1–1:25, Dec. 2011. ISSN 0098-3500. DOI: [10.1145/2049662.2049663.](http://dx.doi.org/10.1145/2049662.2049663) URL [https://doi.org/10.1145/2049662.2049663.](https://doi.org/10.1145/2049662.2049663) [16] I. Dunning, J. Huchette, and M. Lubin. JuMP: A Modeling Language for Mathematical Optimization. _SIAM_ _Review_, 59(2):295–320, Jan. 2017. ISSN 0036-1445. DOI: [10/gftshn.](http://dx.doi.org/10/gftshn) URL [https://epubs.siam.org/doi/abs/10.1137/15M1020575.](https://epubs.siam.org/doi/abs/10.1137/15M1020575) [17] S. A. Forth. An efficient overloaded implementation of forward mode automatic differentiation in MATLAB. _ACM_ _Transactions_ _on_ _Mathematical_ _Software_, 32(2):195–222, June 2006. ISSN 00983500. DOI: [10.1145/1141885.1141888.](http://dx.doi.org/10.1145/1141885.1141888) URL [https://dl.acm.org/doi/10.1145/1141885.1141888.](https://dl.acm.org/doi/10.1145/1141885.1141888) [18] D. Gaur, S. Hossain, and R. R. Singh. Star Bicolouring of Bipartite Graphs. _Algorithms_, 17 (9):377, Sept. 2024. ISSN 1999-4893. DOI: [10.3390/a17090377.](http://dx.doi.org/10.3390/a17090377) URL [https://www.mdpi.com/](https://www.mdpi.com/1999-4893/17/9/377) [1999-4893/17/9/377.](https://www.mdpi.com/1999-4893/17/9/377) [19] D. R. Gaur, S. Hossain, and A. Saha. Determining Sparse Jacobian Matrices Using TwoSided Compression: An Algorithm and Lower Bounds. In J. Bélair, I. A. Frigaard, H. Kunze, R. Makarov, R. Melnik, and R. J. Spiteri, editors, _Mathematical_ _and_ _Computational_ _Approaches_ _in_ _Advancing_ _Modern_ _Science_ _and_ _Engineering_, pages 425–434, Cham, 2016. Springer Interna tional Publishing. ISBN 978-3-319-30379-6. DOI: [10.1007/978-3-319-30379-6_39.](http://dx.doi.org/10.1007/978-3-319-30379-6_39) [20] A. H. Gebremedhin, F. Manne, and A. Pothen. What Color Is Your Jacobian? Graph Coloring for Computing Derivatives. _SIAM_ _Review_, 47(4):629–705, Jan. 2005. ISSN 0036-1445. DOI: [10/cmwds4.](http://dx.doi.org/10/cmwds4) URL [https://epubs.siam.org/doi/abs/10.1137/S0036144504444711.](https://epubs.siam.org/doi/abs/10.1137/S0036144504444711) [21] A. H. Gebremedhin, A. Tarafdar, F. Manne, and A. Pothen. New Acyclic and Star Coloring Algorithms with Application to Computing Hessians. _SIAM_ _Journal_ _on_ _Scientific_ _Computing_, 29(3):1042–1072, Jan. 2007. ISSN 1064-8275. DOI: [10.1137/050639879.](http://dx.doi.org/10.1137/050639879) URL [https://epubs.](https://epubs.siam.org/doi/abs/10.1137/050639879) [siam.org/doi/abs/10.1137/050639879.](https://epubs.siam.org/doi/abs/10.1137/050639879) [22] A. H. Gebremedhin, A. Tarafdar, A. Pothen, and A. Walther. Efficient Computation of Sparse Hessians Using Coloring and Automatic Differentiation. _INFORMS_ _Journal_ _on_ _Computing_, 21 (2):209–223, May 2009. ISSN 1091-9856. DOI: [10.1287/ijoc.1080.0286.](http://dx.doi.org/10.1287/ijoc.1080.0286) URL [https://pubsonline.](https://pubsonline.informs.org/doi/abs/10.1287/ijoc.1080.0286) [informs.org/doi/abs/10.1287/ijoc.1080.0286.](https://pubsonline.informs.org/doi/abs/10.1287/ijoc.1080.0286) [23] A. H. Gebremedhin, D. Nguyen, M. M. A. Patwary, and A. Pothen. ColPack: Software for graph coloring and related problems in scientific computing. _ACM_ _Transactions_ _on_ _Mathematical_ _Software_, 40(1):1:1–1:31, Oct. 2013. ISSN 0098-3500. DOI: [10.1145/2513109.2513110.](http://dx.doi.org/10.1145/2513109.2513110) URL [https://dl.acm.org/doi/10.1145/2513109.2513110.](https://dl.acm.org/doi/10.1145/2513109.2513110) [24] S. Gowda, Y. Ma, V. Churavy, A. Edelman, and C. Rackauckas. Sparsity Programming: Automated Sparsity-Aware Optimizations in Differentiable Programming. In _Program_ _Transfor-_ _mations_ _for_ _ML_ _Workshop_ _at_ _NeurIPS_ _2019_, Sept. 2019. URL [https://openreview.net/forum?](https://openreview.net/forum?id=rJlPdcY38B) [id=rJlPdcY38B.](https://openreview.net/forum?id=rJlPdcY38B) [25] M. Goyal and S. Hossain. Bi-Directional Determination of Sparse Jacobian Matrices: Approaches and Algorithms. _Electronic_ _Notes_ _in_ _Discrete_ _Mathematics_, 25:73–80, Aug. 2006. ISSN 15710653. DOI: [10.1016/j.endm.2006.06.091.](http://dx.doi.org/10.1016/j.endm.2006.06.091) URL [https://www.sciencedirect.com/science/article/](https://www.sciencedirect.com/science/article/pii/S1571065306000722) [pii/S1571065306000722.](https://www.sciencedirect.com/science/article/pii/S1571065306000722) [26] A. Griewank and A. Walther. _Evaluating_ _Derivatives:_ _Principles_ _and_ _Techniques_ _of_ _Algorithmic_ _Differentiation_ . Society for Industrial and Applied Mathematics, Philadelphia, PA, 2nd ed edition, 2008. ISBN 978-0-89871-659-7. [URL https://epubs.siam.org/doi/book/10.1137/1.9780898717761.](https://epubs.siam.org/doi/book/10.1137/1.9780898717761) [27] A. Griewank, D. Juedes, and J. Utke. Algorithm 755: ADOL-C: A package for the automatic differentiation of algorithms written in C/C++. _ACM_ _Transactions_ _on_ _Mathematical_ _Software_, 22(2):131–167, June 1996. ISSN 0098-3500. DOI: [10.1145/229473.229474.](http://dx.doi.org/10.1145/229473.229474) URL [https://dl.acm.](https://dl.acm.org/doi/10.1145/229473.229474) [org/doi/10.1145/229473.229474.](https://dl.acm.org/doi/10.1145/229473.229474) [28] L. Hascoet and V. Pascual. The Tapenade automatic differentiation tool: Principles, model, and specification. _ACM_ _Trans._ _Math._ _Softw._, 39(3):20:1–20:43, May 2013. ISSN 0098-3500. DOI: [10.1145/2450153.2450158.](http://dx.doi.org/10.1145/2450153.2450158) URL [https://dl.acm.org/doi/10.1145/2450153.2450158.](https://dl.acm.org/doi/10.1145/2450153.2450158) [29] A. Hill and G. Dalle. Sparser, Better, Faster, Stronger: Efficient Automatic Differentiation for Sparse Jacobians and Hessians, Jan. 2025. URL [http://arxiv.org/abs/2501.17737.](http://arxiv.org/abs/2501.17737) [30] A. K. M. S. Hossain and T. Steihaug. Computing a sparse Jacobian matrix by rows and columns. _Optimization_ _Methods_ _and_ _Software_, 10(1):33–48, Jan. 1998. ISSN 1055-6788. DOI: [10.1080/10556789808805700.](http://dx.doi.org/10.1080/10556789808805700) URL [https://doi.org/10.1080/10556789808805700.](https://doi.org/10.1080/10556789808805700) [31] S. Hossain and T. Steihaug. Graph models and their efficient implementation for sparse Jacobian matrix determination. _Discrete_ _Applied_ _Mathematics_, 161(12):1747–1754, Aug. 2013. ISSN 0166-218X. DOI: [10.1016/j.dam.2012.12.010.](http://dx.doi.org/10.1016/j.dam.2012.12.010) URL [https://www.sciencedirect.com/science/](https://www.sciencedirect.com/science/article/pii/S0166218X12004647) [article/pii/S0166218X12004647.](https://www.sciencedirect.com/science/article/pii/S0166218X12004647) [32] D. Juedes and J. Jones. Coloring Jacobians revisited: A new algorithm for star and acyclic bicoloring. _Optimization_ _Methods_ _and_ _Software_, 27(2):295–309, Apr. 2012. ISSN 1055-6788. DOI: [10.1080/10556788.2011.606575.](http://dx.doi.org/10.1080/10556788.2011.606575) URL [https://doi.org/10.1080/10556788.2011.606575.](https://doi.org/10.1080/10556788.2011.606575) 20 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] [33] D. W. Juedes and J. S. Jones. A generic framework for approximation analysis of greedy algorithms for star bicoloring. _Optimization_ _Methods_ _and_ _Software_, 36(4):869–890, July 2021. ISSN 1055-6788. DOI: [10.1080/10556788.2019.1649671.](http://dx.doi.org/10.1080/10556788.2019.1649671) URL [https://doi.org/10.1080/10556788.](https://doi.org/10.1080/10556788.2019.1649671) [2019.1649671.](https://doi.org/10.1080/10556788.2019.1649671) [34] JuliaDiff contributors. JuliaDiff/SparseDiffTools.jl, Oct. 2024. URL [https://github.com/](https://github.com/JuliaDiff/SparseDiffTools.jl) [JuliaDiff/SparseDiffTools.jl.](https://github.com/JuliaDiff/SparseDiffTools.jl) [35] S. P. Kolodziej, M. Aznaveh, M. Bullock, J. David, T. A. Davis, M. Henderson, Y. Hu, and R. Sandstrom. The SuiteSparse Matrix Collection Website Interface. _Journal_ _of_ _Open_ _Source_ _Software_, 4(35):1244, Mar. 2019. ISSN 2475-9066. DOI: [10.21105/joss.01244.](http://dx.doi.org/10.21105/joss.01244) URL [https://joss.theoj.org/papers/10.21105/joss.01244.](https://joss.theoj.org/papers/10.21105/joss.01244) [36] X. T. Liu, J. Firoz, A. H. Gebremedhin, and A. Lumsdaine. NWHy: A Framework for Hypergraph Analytics: Representations, Data structures, and Algorithms. In _2022_ _IEEE_ _International_ _Parallel_ _and_ _Distributed_ _Processing_ _Symposium_ _Workshops_ _(IPDPSW)_, pages 275–284, May 2022. DOI: [10.1109/IPDPSW55747.2022.00057.](http://dx.doi.org/10.1109/IPDPSW55747.2022.00057) URL [https://ieeexplore.ieee.org/abstract/](https://ieeexplore.ieee.org/abstract/document/9835472) [document/9835472.](https://ieeexplore.ieee.org/abstract/document/9835472) [37] M. Lubin, O. Dowson, J. D. Garcia, J. Huchette, B. Legat, and J. P. Vielma. JuMP 1.0: Recent improvements to a modeling language for mathematical optimization. _Mathematical_ _Programming_ _Computation_, June 2023. ISSN 1867-2949, 1867-2957. DOI: [10.1007/s12532-023-](http://dx.doi.org/10.1007/s12532-023-00239-3) [00239-3.](http://dx.doi.org/10.1007/s12532-023-00239-3) URL [https://link.springer.com/10.1007/s12532-023-00239-3.](https://link.springer.com/10.1007/s12532-023-00239-3) [38] S. T. McCormick. Optimal approximation of sparse hessians and its equivalence to a graph coloring problem. _Mathematical_ _Programming_, 26(2):153–171, June 1983. ISSN 1436-4646. DOI: [10.1007/BF02592052.](http://dx.doi.org/10.1007/BF02592052) URL [https://doi.org/10.1007/BF02592052.](https://doi.org/10.1007/BF02592052) [39] S. H. K. Narayanan, B. Norris, and B. Winnicka. ADIC2: Development of a component source transformation system for differentiating C and C++. _Procedia_ _Computer_ _Science_, 1 (1):1845–1853, May 2010. ISSN 1877-0509. DOI: [10.1016/j.procs.2010.04.206.](http://dx.doi.org/10.1016/j.procs.2010.04.206) URL [https:](https://www.sciencedirect.com/science/article/pii/S1877050910002073) [//www.sciencedirect.com/science/article/pii/S1877050910002073.](https://www.sciencedirect.com/science/article/pii/S1877050910002073) [40] S. H. K. Narayanan, B. Norris, P. Hovland, D. C. Nguyen, and A. H. Gebremedhin. Sparse Jacobian Computation Using ADIC2 and ColPack. _Procedia_ _Computer_ _Science_, 4:2115–2123, Jan. 2011. ISSN 1877-0509. DOI: [10.1016/j.procs.2011.04.231.](http://dx.doi.org/10.1016/j.procs.2011.04.231) URL [https://www.sciencedirect.](https://www.sciencedirect.com/science/article/pii/S1877050911002894) [com/science/article/pii/S1877050911002894.](https://www.sciencedirect.com/science/article/pii/S1877050911002894) [41] M. J. D. Powell and Ph. L. Toint. On the Estimation of Sparse Hessian Matrices. _SIAM_ _Journal_ _on_ _Numerical_ _Analysis_, 16(6):1060–1074, Dec. 1979. ISSN 0036-1429. DOI: [10.1137/0716078.](http://dx.doi.org/10.1137/0716078) URL [https://epubs.siam.org/doi/abs/10.1137/0716078.](https://epubs.siam.org/doi/abs/10.1137/0716078) [42] M. Schubert. Mfschubert/sparsejac, Sept. 2024. URL [https://github.com/mfschubert/sparsejac.](https://github.com/mfschubert/sparsejac) [43] A. Walther. Getting Started with ADOL-C. _DROPS-_ _IDN/v2/document/10.4230/DagSemProc.09061.10_, 2009. DOI: [10.4230/DagSemProc.09061.10.](http://dx.doi.org/10.4230/DagSemProc.09061.10) URL [https://drops.dagstuhl.de/entities/document/10.4230/DagSemProc.09061.10.](https://drops.dagstuhl.de/entities/document/10.4230/DagSemProc.09061.10) [44] J. Willkomm, C. H. Bischof, and H. M. Bücker. A new user interface for ADiMat: Toward accurate and efficient derivatives of MATLAB programmes with ease of use. _International_ _Journal_ _of_ _Computational_ _Science_ _and_ _Engineering_, 9(5-6):408–415, Jan. 2014. ISSN 1742-7185. DOI: [10.1504/IJCSE.2014.064526.](http://dx.doi.org/10.1504/IJCSE.2014.064526) URL [https://www.inderscienceonline.com/doi/abs/10.1504/](https://www.inderscienceonline.com/doi/abs/10.1504/IJCSE.2014.064526) [IJCSE.2014.064526.](https://www.inderscienceonline.com/doi/abs/10.1504/IJCSE.2014.064526) [45] S. J. Wright. _Primal-Dual_ _Interior-Point_ _Methods_ . SIAM, Jan. 1997. ISBN 978-1-61197-145-3. [46] W. Xu and T. F. Coleman. Efficient (Partial) Determination of Derivative Matrices via Automatic Differentiation. _SIAM_ _Journal_ _on_ _Scientific_ _Computing_, 35(3):A1398–A1416, Jan. 2013. ISSN 1064-8275. DOI: [10.1137/11085061X.](http://dx.doi.org/10.1137/11085061X) URL [https://epubs.siam.org/doi/abs/10.1137/11085061X.](https://epubs.siam.org/doi/abs/10.1137/11085061X) Appendix A. Implementation details. We describe some implementation details for `SMC`, which improve or extend the algorithms presented in Gebremedhin et al. [20, 21, 22, 23]. The detailed pseudocode of every algorithm is given in Appendix C. A.1. Graph storage. A.1.1. Adjacency graph. The adjacency graph _Ga_ of a symmetric matrix _A_ is stored as a Compressed Sparse Column (CSC) encoding with the help of two integer vectors `colptr` and `rowval` . We assume that the row indices in `rowval` are sorted in increasing order within each column, as is commonly done in sparse matrix libraries to facilitate traversal and efficient access. Note that by symmetry of _A_, it is also a Compressed Sparse Row (CSR) encoding of _A_ . A minor issue is posed by non-zero diagonal coefficients: they may be present in the original matrix, but they are not [toc] Revisiting sparse matrix coloring and bicoloring 21 explicitly represented in the adjacency graph (which has no self-loops by definition). Thus, each iteration over neighbors of a vertex _i_ must remember to skip _i_ itself if encountered. Additionally, for star and acyclic colorings, we need a mapping from edges to unique integer indices. To achieve this, we construct a vector `edge_to_index` of the same length as the number of nonzeros in _A_, assigning a unique integer _k_ to each edge ( _i, j_ ) with _i̸_ = _j_ . In particular, this vector ensures that the off-diagonal entries of _A_ <sup>ˆ</sup>, a sparse CSC matrix defined by `colptr`, `rowval`, and `nzval=edge_to_index`, satisfy _A_ <sup>ˆ</sup> _ij_ = _A_ <sup>ˆ</sup> _ji_ = _k_ . Algorithm C.1 describes how to build this vector from the sparsity pattern of _A_ . This approach is faster for grouped neighbor accesses than a container that stores unique key-value pairs ( _i, j_ ) _�→_ _k_, such as a dictionary. Conversely, `ColPack` implements the mapping between edges and indices using a `C++` `map`, which incurs additional overhead due to dynamic memory allocation and treebased lookups. For the remainder of the algorithms, we regroup these three vectors into a structure called `adjacency_graph` and, for a given vertex `v`, we use the procedures `neighbors(adjacency_graph,` `v)` and `indexed_neighbors(adjacency_graph,` `v)` to return the neighbors (with the associated edge indices if needed) other than `v` . A.1.2. Bipartite graph. For the bipartite graph _Gb_, dual CSC and CSR encodings of _A_ are necessary for optimal performance. The CSC version efficiently maps each column _j_ to its row neighbors, and the CSR version efficiently maps each row _i_ to its column neighbors. At the cost of twice the initial memory space (when _A_ is not structurally symmetric), this allows efficient iteration over neighbors for both parts of the vertex space. To save memory, both CSC and CSR structures are manipulated without storing the nonzero values of _A_ . Algorithm C.2 details the conversion process between the CSC and CSR formats of _A_ . We assume that row indices are sorted in increasing order within each column for the conversion. A.2. Colorings. A.2.1. Partial distance-2 coloring. We implement Algorithm 3.2 of Gebremedhin et al. [20] without any modification. A.2.2. Star coloring. We implement Algorithm 4.1 of Gebremedhin et al. [21] without using hash tables, as detailed in Algorithm C.3. The original algorithm did not assign a hub to trivial stars. However, the corresponding decompression routine requires that every star have a designated hub. To address this, we choose an arbitrary hub for trivial stars but encode it as a negative value _−h_ . This convention not only makes trivial stars easily distinguishable from non-trivial ones during star coloring and post-processing but also simplifies the decompression process. A.2.3. Acyclic coloring. We implement Algorithm 3.1 of Gebremedhin et al. [21] without using hash tables, as detailed in Algorithm C.5. To efficiently build the 2-colored trees, we use a disjoint-set structure that requires two integer vectors `parents` and `ranks`, as well as an integer `nt` to keep track of the current number of trees. In the rest of the paper, this data structure is referred to as `forest` . Three essential routines are implemented on this structure: `create_forest`, `find_root` and `root_union` . They are detailed in Algorithm C.4. Note that the edge index used to represent the root in the structure `forest` does not correspond to the actual tree root vertex. Instead, the selected “root” is maintained to minimize the tree’s height (i.e., it is chosen following a union-by-rank strategy to optimize path compression). A.2.4. Star and acyclic bicoloring. To perform star and acyclic bicoloring, we build the adjacency graph of the augmented symmetric matrix _H_ (2.1), derived from 22 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] a rectangular matrix _J_ . This can be done by efficiently combining Algorithm C.1 and Algorithm C.2. To compute the seeds for the products _Ju_ and _J_ <sup>_⊤_</sup> _v_, we employ the vectors `row_colors` and `column_colors` produced by Algorithm 2.1. Additionally, we use `sym_to_row` and `sym_to_col` (also generated by Algorithm 2.1) along with the relation (2.2) for decompression. A.2.5. Post-processing. Detecting the trivial structures among the stars and trees is simple because we only need to check whether the number of vertices in each structure is exactly two (or one edge). However, in acyclic coloring, we need to distinguish the stars from the normal trees. To do that, we determine a boolean vector `is_star` that indicates for each tree whether it is a star (potentially trivial) or not. We can compute this concurrently with the reverse BFS orders of the two-colored trees (Algorithm C.7). Note that we can reuse the vector `forbidden_colors` needed in both star and acyclic colorings (Algorithms 3.1 and 4.1 of Gebremedhin et al. [21]) for the vector `offsets` during post-processing (Algorithm 3.1). A.3. Decompression. In `SMC`, we optimize the decompression of all our colorings for sparse CSC matrices with a generic fallback for matrices in other formats. Except for row and column coloring, where the decompression is straightforward, the decompression of symmetric colorings and derived bicolorings uses the algorithms _DirectRecover2_ and _IndirectRecover_ from Gebremedhin et al. [22], combined with new additional strategies. A.3.1. Direct decompression. For direct decompression, we found it more efficient to use linear indexing and precompute the positions of nonzeros in the compressed matrix _B_ . We store them in a dedicated vector `compressed_indices` . `nzval[k]` `=` `B[compressed_indices[k]]` for `k` = 1 _, . . .,_ `nnzA` _._ For example, after column coloring, a coefficient _Aij_ is recovered from _Bic_ where `c` `=` `col_colors[j]` at the linear index ( _c −_ 1) _× m_ + _i_ when _B_ is column-ordered and 1-based indexed. Although the recovery is simple for row or column coloring, it becomes more complex and less parallel for star coloring and bicoloring. We need to use the stars to determine which vertex’s color of a edge ( _i, j_ ) is needed to recover a coefficient _Aij_ . Note that an additional integer vector `A_indices` is needed for star bicoloring to specify which nonzeros are recovered from _Br_ and _Bc_ : `nzval[A_indices[k]]` = _Bc_ `[compressed_indices[k]]` _,_ for `k` = 1 _, . . ., ℓ,_ `nzval[A_indices[k]]` = _Br_ `[compressed_indices[k]]` _,_ for `k` = _ℓ_ + 1 _, . . .,_ `nnzA` _._ The variable _ℓ_ denotes the number of nonzeros of _A_ recovered from _Bc_ . A.3.2. Decompression by substitution. For acyclic coloring and bicoloring, the decompression step relies on traversing the two-colored trees. However, existing work does not explain how to reconstruct the structure of these trees from their disjoint-set representation. While the coloring phase identifies which edges belong to the same tree, it does not reveal how each tree can be traversed from its leaves to its root, following a reverse breadth-first search (BFS) order. Our goal is to clarify how this ordering can be computed and extracted from the structure `forest` . Once determined, the edges within each tree are sorted according to the order in which they must be processed. [toc] Revisiting sparse matrix coloring and bicoloring 23 In this ordering, each edge is oriented so that its first vertex is a leaf (after pruning previously processed edges), and its second vertex is an internal node. This convention enables the direct application of _IndirectRecover_ from Gebremedhin et al. [22]. The reconstruction of the trees is described in Algorithm C.6, and the computation of the reverse BFS order is presented in Algorithm C.7. We use the fact that a tree with `ne` edges has exactly `ne+1` vertices in these routines. Note that the vector `ranks` from the structure `forest` can be repurposed to store `root_to_tree` in Algorithm C.6. Likewise, the array `first_visit_to_tree` used during acyclic coloring can be reused to store `reverse_bfs_orders` in Algorithm C.7. With this approach, the decompression of each tree can be performed in parallel. However, it offers less parallelism than direct decompression, since parallelism occurs across the number of trees rather than across the number of nonzeros. Moreover, the number of edges per tree may vary significantly, which may require load balancing to efficiently exploit this parallelism. For this reason, we emphasize that _IndirectRecover_ from Gebremedhin et al. [22] is equivalent to solving a sparse triangular system in which all coefficients are either 0 or 1, the unknowns correspond to the nonzeros, and the right-hand side is a subset of the entries of the matrix _B_ . An alternative is to explicitly compute the inverses of all the sparse triangular matrices needed. These inverses remain triangular and contain only -1 (off-diagonal), 0, and 1 (diagonal) as entries. All of these inverse matrices can then be assembled into a single large sparse matrix, and the full vector of `nzval` can be recovered through a single sparse matrix-vector multiplication with `B[compressed_indices]` . This approach might require significantly more storage, but it is likely the most efficient way to exploit SIMD architectures such as GPUs. A.4. Vertex orderings. Our implementation of vertex orderings follows Section 5.1 of Gebremedhin et al. [23]. The authors describe three different orderings using a common framework, that of dynamic degree-based orderings. Each vertex in the graph gets assigned a dynamic degree, which evolves as the ordering progresses and the permutation _π_ of vertices gets built. More precisely, the back degree of a vertex _v_ is the number of neighbors that appear before _v_ in the permutation _π_, while the forward degree of _v_ is the number of neighbors that appear after _v_ . As the permutation _π_ = _{v_ 1 _, . . ., vn}_ is grown iteratively, either from _v_ 1 to _vn_ or from _vn_ to _v_ 1, the dynamic degrees (back or forward) evolve. Since these degrees are used to select which vertex will be added to the permutation next, we need an efficient way to keep track of them. Gebremedhin et al. [23, Figure 2] propose a bucket sort mechanism to achieve this goal. They use one variable-size bucket per possible value of the dynamic degree. Whenever the dynamic degree of a vertex changes, it gets moved one bucket up or one bucket down, and appended to the end of the destination bucket. This is rather straightforward to implement, but requires one stack-like data structure per bucket, whose size will increase or decrease and cannot be predicted ahead of time. To improve memory locality and remove the need for variable-sized containers, we suggest an alternative where all buckets are stored inside the same vector, and the limits of each bucket (an interval of integers) are kept updated separately. The key is to allow modification of a bucket either from the start or from the end. That way, when a vertex _v_ moves up from bucket _d_ to bucket _d_ + 1, bucket _d_ shrinks from the right and bucket _d_ + 1 grows to the left. When a vertex _v_ moves down from bucket _d_ to bucket _d −_ 1, bucket _d_ shrinks from the left and bucket _d −_ 1 grows to the right. In both cases, the total amount of storage necessary remains constant and predictable. The two algorithms are detailed and compared in Algorithm C.8 and Algorithm C.9, 24 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] on the special case of a vertex whose dynamic degree needs to increase by one. Appendix B. Benchmarks. B.1. Setup. The benchmarks are run on a 14-inch MacBook Pro M3 (2023) with 36 GB of RAM, using Julia v1.11.5 in single-threaded mode. `SMC` is called through its native Julia interface, which accepts CSC matrices, while `ColPack` is called through its command line interface, which accepts `.mtx` matrix files. We use a compiled version of `ColPack` without OpenMP (through `ColPack.jl` v0.5.0), along with `SparseMatrixColorings.jl` v0.4.19. B.2. Test matrices. The test matrices are retrieved from the `SuiteSparse` matrix collection [15, 35]. We describe their main features in Table 6.1. B.3. Number of colors. We first investigate whether or not our `SMC` implementation is consistent with the results returned by `ColPack` . This is done for each of the following orders: smallest last (SL), incidence degree (ID), largest first (LF), dynamic largest first (DLF) and natural (N). Boldfaced numbers indicate the minimum number of colors for a given instance across all orders. We recall that some implementation differences between `SMC` and `ColPack` can affect the number of colors: _•_ `SMC` has a completely different algorithm for star bicoloring (Section 2); _•_ The natural order for bicoloring differs: `SMC` colors columns before rows, whereas `ColPack` does the opposite; _•_ `SMC` calls a post-processing routine after star and acyclic coloring algorithms (Section 3), which can reduce the number of colors if some diagonal coefficients are zero. To minimize discrepancies, we always imitate `ColPack` ’s stack-based ordering algorithm instead of leveraging our own vector-based improvement (Appendix A.4). B.3.1. Unidirectional and symmetric colorings. Results for row coloring are presented in Table B.1, for column coloring in Table B.2, for star coloring in Table B.3, for acyclic coloring in Table B.4. In these four tables, underlined numbers indicate a discrepancy between `SMC` and `ColPack` . Each table contains at most one instance where the two libraries differ (usually by a couple of colors), which suggests that both implementations give very similar results. SL ID LF DLF N name CP SMC CP SMC CP SMC CP SMC CP SMC lp_cre_a 14 14 14 14 14 14 14 14 16 16 lp_ken_11 4 4 4 4 4 4 5 5 5 5 lp_ken_13 4 4 5 5 5 5 5 5 4 4 lp_maros_r7 80 80 88 88 100 100 113 113 72 72 lp_cre_d 15 15 15 15 13 13 14 14 15 15 lp_ken_18 4 4 5 5 5 5 5 5 5 5 af23560 42 42 43 <u>42</u> 43 <u>36</u> 60 <u>59</u> 43 <u>32</u> e40r0100 70 70 71 71 85 85 86 86 87 87 cage11 64 64 67 67 67 67 70 70 81 81 cage12 67 67 72 72 73 73 79 79 96 96 Table B.1: Number of colors for row coloring. B.3.2. Bidirectional colorings. Results for star bicoloring are presented in Table B.5, and for acyclic bicoloring in Table B.6. Here, we observe that the lowest [toc] Revisiting sparse matrix coloring and bicoloring 25 SL ID LF DLF N name CP SMC CP SMC CP SMC CP SMC CP SMC lp_cre_a 360 360 360 360 360 360 360 360 360 360 lp_ken_11 125 125 124 124 128 128 122 122 130 130 lp_ken_13 171 171 171 171 174 174 170 170 176 176 lp_maros_r7 83 83 90 90 70 70 114 114 74 74 lp_cre_d 808 808 808 808 808 808 808 808 813 813 lp_ken_18 325 325 326 326 328 328 325 325 330 330 af23560 42 42 42 42 43 <u>44</u> 59 59 44 <u>32</u> e40r0100 70 70 71 71 87 87 85 85 95 95 cage11 64 64 67 67 67 67 70 70 81 81 cage12 67 67 72 72 73 73 79 79 96 96 Table B.2: Number of colors for column coloring. SL ID LF DLF N name CP SMC CP SMC CP SMC CP SMC CP SMC 598a 23 23 23 23 27 27 28 28 28 28 144 24 24 25 25 28 28 30 30 29 29 m14b 28 28 27 27 36 36 38 38 32 32 auto 27 27 28 <u>29</u> 36 36 34 34 32 32 Table B.3: Number of colors for star coloring. SL ID LF DLF N name CP SMC CP SMC CP SMC CP SMC CP SMC 598a 12 12 12 <u>11</u> 12 12 12 12 13 13 144 13 13 13 13 13 13 14 14 14 14 m14b 14 14 14 14 15 15 16 16 18 18 auto 14 14 15 15 15 15 16 16 16 16 Table B.4: Number of colors for acyclic coloring. number of colors is nearly always provided by an `SMC` implementation, and that acyclic bicoloring leads to fewer colors than star bicoloring, as expected. In both star and acyclic bicoloring, the number of colors produced by the `SMC` implementation is heavily dependent on the ordering, and some orderings perform very poorly. We conjecture that this may be due to the orderings being applied to the augmented symmetric matrix, whereas they were designed for a different graph representation. Designing orderings suitable for the `SMC` approach is an interesting direction for future research. SL ID LF DLF N name CP SMC CP SMC CP SMC CP SMC CP SMC lp_cre_a 27 31 24 370 23 364 21 365 18 16 lp_ken_11 128 68 129 128 8 134 5 133 6 5 lp_ken_13 176 166 177 169 8 180 6 182 5 4 lp_maros_r7 131 80 153 91 130 134 71 116 73 72 lp_cre_d 38 275 25 815 23 811 17 810 17 15 lp_ken_18 331 241 331 332 8 334 6 337 6 5 af23560 75 53 74 77 67 71 51 105 44 32 e40r0100 99 155 98 72 93 83 89 147 88 87 cage11 96 76 105 81 94 87 69 158 82 81 cage12 102 106 114 90 104 97 74 121 97 96 Table B.5: Number of colors for star bicoloring. 26 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] SL ID LF DLF N name SMC SMC SMC SMC SMC lp_cre_a 43 118 116 117 12 lp_ken_11 10 11 12 12 4 lp_ken_13 10 10 11 10 4 lp_maros_r7 159 97 115 115 72 lp_cre_d 87 152 151 148 13 lp_ken_18 10 10 9 10 4 af23560 60 61 57 87 45 e40r0100 157 72 83 148 87 cage11 46 45 52 125 79 cage12 47 45 55 99 93 Table B.6: Number of colors for acyclic bicoloring ( `SMC` only). B.4. Timings. We have established that the `SMC` and `ColPack` algorithms are, at minimum, directly comparable. The next question is one of performance: can a Julia implementation compete with the speed of an optimized `C++` library? To answer it, we run the function of interest five times and record the minimum runtime for each package. Then, we display the ratio of these minimum runtimes, `SMC` over `ColPack` . Ratios under 1 indicates that `SMC` is faster, while ratios above 1 show that `ColPack` stays ahead. We do not measure the time it takes to process the matrix and construct the graph (which is format-dependent): we only measure the ordering time and the subsequent coloring time once the graph is available. B.4.1. Coloring times. We start with the results for coloring times in the case of the natural order, presented in Table B.7 and Table B.8. The unidirectional colorings in `SMC` are generally as fast as `ColPack` ’s, but our symmetric and bidirectional colorings can be up to four times faster. The slight overhead in the unidirectional routines stems from Julia’s bounds checking on array accesses, an operation not present in `C++`, which may modestly constrain compiler optimizations. Note that for acyclic bicoloring, we compute the runtime ratio compared to `ColPack` ’s star bicoloring, for lack of an equivalent algorithm. column row bidirectional <sup>_⋆_</sup> name star acyclic lp_cre_a 1.2 0.808 0.27 0.563 lp_ken_11 1.11 1.08 0.202 0.424 lp_ken_13 1.17 1.08 0.22 0.405 lp_maros_r7 0.899 1.13 0.568 1.22 lp_cre_d 1.37 1.16 0.227 0.497 lp_ken_18 1.22 1.22 0.201 0.442 af23560 1.35 1.43 0.377 0.973 e40r0100 1.17 1.31 0.615 1.22 cage11 1.23 1.28 0.414 1.2 cage12 1.28 1.33 0.393 1.28 Table B.7: Coloring time ratios ( `SMC` / `ColPack` ) for row coloring, column coloring and bicoloring with natural order. _⋆_ both compared to star bicoloring in `ColPack` unidirectional name star acyclic 598a 0.271 0.449 144 0.267 0.455 m14b 0.277 0.449 auto 0.304 0.489 Table B.8: Coloring time ratios ( `SMC` / `ColPack` ) for star and acyclic coloring with natural order. B.4.2. Ordering times. We present results for the ordering subroutines in Table B.9, Table B.10, and Table B.11. As we can see, `SMC` is usually within a factor of [toc] Revisiting sparse matrix coloring and bicoloring 27 2 of `ColPack` ’s ordering performance. Note that for bicoloring, `SMC` runs the ordering on the augmented adjacency graph, while `ColPack` runs it on the initial bipartite graph, which makes the timings harder to compare meaningfully. name SL ID LF DLF lp_cre_a 0.83 1.04 0.84 1.06 lp_ken_11 1.18 1.49 1.57 1.35 lp_ken_13 1.16 1.37 1.63 1.39 lp_maros_r7 1.3 1.34 1.4 0.91 lp_cre_d 1.11 1.18 1.04 1.24 lp_ken_18 1.22 1.47 1.97 1.37 af23560 1.46 1.73 1.89 1.05 e40r0100 0.87 0.97 1.21 0.86 cage11 1.17 1.19 1.2 1.22 cage12 1.24 1.23 1.29 1.31 Table B.9: Ordering time ratios ( `SMC` / `ColPack` ) for row coloring. name SL ID LF DLF lp_cre_a 1.36 0.91 1.86 1.42 lp_ken_11 1.82 1.29 2.41 1.46 lp_ken_13 1.57 1.28 2.48 1.58 lp_maros_r7 1.38 1.22 1.36 0.94 lp_cre_d 1.64 1.39 1.58 1.58 lp_ken_18 1.78 1.41 2.94 1.71 af23560 1.5 1.7 1.7 1 e40r0100 0.95 1 1.28 0.95 cage11 1.18 1.08 1.19 1.24 cage12 1.24 1.12 1.26 1.31 Table B.10: Ordering time ratios ( `SMC` / `ColPack` ) for column coloring. name SL ID LF DLF 598a 1.71 1.68 4.96 1.59 144 1.76 1.74 5.81 1.9 m14b 1.84 1.67 5.89 1.97 auto 1.94 1.83 7.41 1.73 Table B.11: Ordering time ratios ( `SMC` / `ColPack` ) for star coloring. 28 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] Appendix C. Pseudocode. In this appendix, we present the detail of the algorithms we adapted or designed for ordering, coloring and decompression. Input: _•_ An integer `n` corresponding to the dimension of a symmetric matrix _A_ . _•_ An integer `nnzA` corresponding to the number of non-zeros of _A_ . _•_ An integer vector `colptr` of length `n+1` . _•_ An integer vector `rowval` of length `nnzA` . _•_ An integer vector `offsets` of length `n` . Output: _•_ An integer vector `edge_to_index` of length `nnzA` . 1: Initialize `offsets[1...n]` _←_ `0` 2: Set `k` _←_ `0` 3: for `j` _←_ `1` to `n` do 4: for `p` _←_ `colptr[j]` to `colptr[j+1]-1` do 5: `i` _←_ `rowval[p]` 6: if `i` `>` `j` then 7: `k` _←_ `k` `+` `1` 8: `edge_to_index[p]` _←_ `k` 9: `q` _←_ `colptr[i]` `+` `offsets[i]` 10: `edge_to_index[q]` _←_ `k` 11: `offsets[i]` _←_ `offsets[i]` `+` `1` 12: end if 13: end for 14: end for 15: return `edge_to_index` Algorithm C.1: Procedure to build the vector `edge_to_index` from a sparse symmetric matrix _A_ stored in CSC format, where the entries in `rowval` for each column must be sorted in ascending order. The arrays use 1-based indexing. [toc] Revisiting sparse matrix coloring and bicoloring 29 Input: _•_ An integer `m` corresponding to the number of rows of _A_ . _•_ An integer `n` corresponding to the number of columns of _A_ . _•_ An integer `nnzA` corresponding to the number of non-zeros of _A_ . _•_ An integer vector `colptr` of length `n+1` . _•_ An integer vector `rowval` of length `nnzA` . Output: _•_ An integer vector `rowptr` of length `m+1` . _•_ An integer vector `colval` of length `nnzA` . 1: Initialize `rowptr[1...m+1]` _←_ `0` 2: for _k_ _←_ `1` to `nnzA` do 3: `i` _←_ `rowval[k]` 4: `rowptr[i]` _←_ `rowptr[i]` `+` `1` 5: end for 6: Set `counter` _←_ `1` 7: for _i ←_ `1` to `m` do 8: `nnz_row` _←_ `rowptr[i]` 9: `rowptr[i]` _←_ `counter` 10: `counter` _←_ `counter` `+` `nnz_row` 11: end for 12: `rowptr[m+1]` _←_ `counter` 13: for _j_ _←_ `1` to `n` do 14: for _p ←_ `colptr[j]` to `colptr[j+1]-1` do 15: `i` _←_ `rowval[p]` 16: `pos` _←_ `rowptr[i]` 17: `colval[pos]` _←_ `j` 18: `rowptr[i]` _←_ `rowptr[i]` `+` `1` 19: end for 20: end for 21: for _i_ _←_ `m` down to `2` do 22: `rowptr[i]` _←_ `rowptr[i-1]` 23: end for 24: `rowptr[1]` _←_ `1` 25: return `rowptr`, `colval` Algorithm C.2: Procedure to convert a sparse matrix _A_ stored in CSC format ( `colptr`, `rowval` ) into its equivalent CSR representation ( `rowptr`, `colval` ). The arrays use 1-based indexing. 30 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] Input: _•_ `adjacency_graph`, `vertices_in_order`, `nv`, `ne` Output: _•_ `color`, `star`, `hub` 1: `color[1,...,nv]` _←_ `0` 2: `forbidden_colors[1,...,nv]` _←_ `0` 3: `first_neighbor[1,...,nv]` _←_ `(0,0,0)` 4: `treated[1,...,nv]` _←_ `0` 5: `star[1,...,ne]` _←_ `0` 6: `hub` _←_ `[ ]` 7: `num_stars` _←_ `0` 8: for each `v` _∈_ `vertices_in_order` do 9: for each `(w,` `index_vw` ) _∈_ `indexed_neighbors(adjacency_graph,` `v)` do 10: if `color[w]` _̸_ = `0` then 11: `forbidden_colors[color[w]]` _←_ `v` 12: `(p,` `q,` `index_pq)` _←_ `first_neighbor[color[w]]` 13: if `p` `==` `v` then 14: if `treated[q]` _̸_ = `v` then 15: for each `x` _∈_ `neighbors(adjacency_graph,` `q)` do 16: if `color[x]` _̸_ = `0` then 17: `forbidden_colors[color[x]]` _←_ `v` 18: end if 19: end for 20: `treated[q]` _←_ `v` 21: end if 22: for each `x` _∈_ `neighbors(adjacency_graph,` `w)` do 23: if `color[x]` _̸_ = `0` then 24: `forbidden_colors[color[x]]` _←_ `v` 25: end if 26: end for 27: `treated[w]` _←_ `v` 28: else 29: `first_neighbor[color[w]]` _←_ `(v,` `w,` `index_vw)` 30: for each `(x,` `index_wx` ) _∈_ `indexed_neighbors(adjacency_graph,` `w)` do 31: if `x` _̸_ = `v` and `color[x]` _̸_ = `0` and `x` `==` `hub[star[index_wx]]` then 32: `forbidden_colors[color[x]]` _←_ `v` 33: end if 34: end for 35: end if 36: end if 37: end for 38: `color[v]` _←_ `min{i` `|` `forgiven_colors[i]` _̸_ = `v` } 39: for each `(w,` `index_vw` ) _∈_ `indexed_neighbors(adjacency_graph,` `v)` do 40: if `color[w]` _̸_ = `0` then 41: `x_exists` _←_ `false` 42: for each `(x,` `index_wx` ) _∈_ `indexed_neighbors(adjacency_graph,` `w)` do 43: if `x` _̸_ = `v` and `color[x]` `==` `color[v]` then 44: `star_wx` _←_ `star[index_wx]` 45: `hub[star_wx]` _←_ `w` 46: `star[index_vw]` _←_ `star_wx` 47: `x_exists` _←_ `true` 48: break 49: end if 50: end for 51: if ( not `x_exists` ) then 52: `(p,` `q,` `index_pq)` _←_ `first_neighbor[color[w]]` 53: if `p` `==` `v` and `q` _̸_ = `w` then 54: `star_vq` _←_ `star[index_pq]` 55: `hub[star_vq]` _←_ `v` 56: `star[index_vw]` _←_ `star_vq` 57: else 58: `num_stars` _←_ `num_stars` `+` `1` 59: `push!(hub,` `-v)` or `push!(hub,` `-w)` 60: `star[index_vw]` _←_ `num_stars` 61: end if 62: end if 63: end if 64: end for 65: end for [toc] Revisiting sparse matrix coloring and bicoloring 31 Procedure `create_forest` ( `ne` ) _•_ Input: An integer `ne` corresponding to the number of edges. _•_ Output: A structure `forest` . 1: `nt` _←_ `ne` 2: `parents[1..ne]` _←_ `[1,` `2,` `...,` `ne]` 3: `ranks[1..ne]` _←_ `[0,` `0,` `...,` `0]` Procedure `find_root` ( `forest`, `index` ) _•_ Input: One edge index, `index`, and the structure `forest` . _•_ Output: The root of the tree containing `index` . 1: if `parents[index]` _̸_ = `index` then 2: `parents[index]` _←_ `find_root(parents[index],` `forest)` 3: end if 4: return `parents[index]` Procedure `root_union` ( `forest`, `root1`, `root2` ) _•_ Input: Two root indices, `root1` and `root2`, and the structure `forest` . _•_ Output: The structure `forest` after merging the trees with roots `root1` and `root2` . 1: if `ranks[root1]` `<` `ranks[root2]` then 2: ( `root1,` `root2` ) _←_ ( `root2,` `root1` ) 3: else if `ranks[root1]` `==` `ranks[root2]` then 4: `ranks[root1]` _←_ `ranks[root1]` + 1 5: end if 6: `parents[root2]` _←_ `root1` 7: `nt` _←_ `nt` `-` `1` Algorithm C.4: Routines related the structure `forest` . 32 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] Input: _•_ `adjacency_graph`, `vertices_in_order`, `nv`, `ne` Output: _•_ `color`, `forest` 1: `color[1,...,nv]` _←_ `0` 2: `forbidden_colors[1,...,nv]` _←_ `0` 3: `first_neighbor[1,...,nv]` _←_ `(0,0,0)` 4: `first_visit_to_tree[1,...,ne]` _←_ `(0,0)` 5: `forest` _←_ `create_forest(ne)` 6: for each `v` _∈_ `vertices_in_order` do 7: for each `(w,` `index_vw` ) _∈_ `indexed_neighbors(adjacency_graph,` `v)` do 8: if `color[w]` _̸_ = 0 then 9: `forbidden_colors[color[w]]` _←_ `v` 10: end if 11: end for 12: for each `w` _∈_ `neighbors(adjacency_graph,` `v)` do 13: if `color[w]` _̸_ = 0 then 14: for each `(x,` `index_wx` ) _∈_ `indexed_neighbors(adjacency_graph,` `w)` do 15: if `color[x]` _̸_ = 0 and `forbidden_colors[color[x]]` _̸_ = `v` then 16: `root_wx` _←_ `find_root(forest,` `index_wx)` 17: `(p,` `q)` _←_ `first_visit_to_tree[root_wx]` 18: if `p` _̸_ = `v` then 19: `first_visit_to_tree[root_wx]` _←_ `(v,` `w)` 20: else if `q` _̸_ = `w` then 21: `forbidden_colors[color[x]]` _←_ `v` 22: end if 23: end if 24: end for 25: end if 26: end for 27: `color[v]` _←_ `min{i` `|` `forgiven_colors[i]` _̸_ = `v` } 28: for each `(w,` `index_vw` ) _∈_ `indexed_neighbors(adjacency_graph,` `v)` do 29: if `color[w]` _̸_ = 0 then 30: `(p,` `q,` `index_pq)` _←_ `first_neighbor[color[w]]` 31: if `p` _̸_ = `v` then 32: `first_neighbor[color[w]]` _←_ `(v,` `w,` `index_vw)` 33: else 34: `root_vw` _←_ `find_root(forest,` `index_vw)` 35: `root_pq` _←_ `find_root(forest,` `index_pq)` 36: `root_union(forest,` `root_vw,` `root_pq)` 37: end if 38: end if 39: end for 40: for each `(w,` `index_vw` ) _∈_ `indexed_neighbors(adjacency_graph,` `v)` do 41: if `color[x]` `==` `color[v]` then 42: `root_vw` _←_ `find_root(forest,` `index_vw)` 43: `root_wx` _←_ `find_root(forest,` `index_wx)` 44: if `root_vw` _̸_ = `root_wx` then 45: `root_union(forest,` `root_vw,` `root_wx)` 46: end if 47: end if 48: end for 49: end for Algorithm C.5: Procedure `acyclic_coloring` . [toc] Revisiting sparse matrix coloring and bicoloring 33 Input: _•_ `adjacency_graph`, `nv`, `ne`, `nt`, `forest` Output: _•_ `nvmax`, `tree_edge_indices`, `tree_vertices`, `tree_neighbor_indices`, `tree_neighbors` 1: `tree_vertices[1,...,ne+nt]` _←_ `0` 2: `tree_neighbor_indices[1,...,ne+nt+1]` _←_ `0` 3: `tree_neighbors[1,...,2*ne]` _←_ `0` 4: `tree_edge_indices[1,...,nt+1]` _←_ `0` 5: `root_to_tree[1,...,ne]` _←_ `0` 6: `visited_trees[1,...,nt]` _←_ `0` 7: `vertex_position[1,...,nt]` _←_ `0` 8: `neighbor_position[1,...,nt]` _←_ `0` 9: `nr` _←_ 0 10: for `index_edge` _←_ 1 to `ne` do 11: `root` _←_ `find_root(forest,` `index_edge)` 12: if `root_to_tree[root]` `==` 0 then 13: `nr` `+=` `1` 14: `root_to_tree[root]` _←_ `nr` 15: end if 16: `index_tree` _←_ `root_to_tree[root]` 17: `tree_edge_indices[index_tree` `+` `1]` `+=` `1` 18: end for 19: `nvmax` _←_ `maximum(tree_edge_indices)` + 1 20: `vertex_position[1]` _←_ 0 21: `neighbor_position[1]` _←_ 0 22: for `k` _←_ `2` to `nt` do 23: `vertex_position[k]` _←_ `vertex_position[k-1]` `+` `tree_edge_indices[k]` `+` `1` 24: `neighbor_position[k]` _←_ `neighbor_position[k-1]` `+` `2` `*` `tree_edge_indices[k]` 25: end for 26: for `j` _←_ `1` to `nv` do 27: for each `(i,` `index_ij` ) _∈_ `indexed_neighbors(adjacency_graph,` `j)` do 28: if `i` _̸_ = `j` then 29: `root` _←_ `find_root(forest,` `index_ij)` 30: `index_tree` _←_ `root_to_tree[root]` 31: `vertex_index` _←_ `vertex_position[index_tree]` 32: if `visited_trees[index_tree]` _̸_ = `j` then 33: `visited_trees[index_tree]` _←_ `j` 34: `vertex_position[index_tree]` `+=` `1` 35: `vertex_index` `+=` `1` 36: `tree_vertices[vertex_index]` _←_ `j` 37: end if 38: `neighbor_position[index_tree]` `+=` `1` 39: `neighbor_index` _←_ `neighbor_position[index_tree]` 40: `tree_neighbors[neighbor_index]` _←_ `i` 41: `tree_neighbor_indices[vertex_index` `+` `1]` `+=` `1` 42: end if 43: end for 44: end for 45: `tree_edge_indices[1]` _←_ 1 46: `tree_neighbor_indices[1]` _←_ 1 47: for `k` = `2` to `nt+1` do 48: `tree_edge_indices[k]` _←_ `tree_edge_indices[k]` `+` `tree_edge_indices[k-1]` 49: `tree_neighbor_indices[k]` _←_ `tree_neighbor_indices[k]` `+` `tree_neighbor_indices[k-1]` 50: end for Algorithm C.6: Procedure to recover the structure of the trees from `forest` . 34 A. MONTOISON, G. DALLE AND A. GEBREMEDHIN [toc] Input: _•_ `nvmax` is the number of vertices in the largest tree of the forest. _•_ `tree_edge_indices` specifies the starting and ending indices of edges for each tree. _•_ `tree_vertices` contains the list of vertices, grouped by tree. _•_ `tree_neighbor_indices` provides the positions of the first and last neighbors for each vertex in `tree_vertices`, within the tree to which the vertex belongs. _•_ `tree_neighbors` is a packed representation of the neighbors of each vertex in `tree_vertices` . Output: _•_ `reverse_bfs_orders` is the edge ordering used for decompression, grouped by tree. _•_ `is_star` is a boolean vector indicating whether each tree is a star. 1: `reverse_bfs_orders[1,...,ne]` _←_ `(0,0)` 2: `degrees[1,...,nv]` _←_ `0` 3: `reverse_mapping[1,...,nv]` _←_ `0` 4: `queue[1,...,nvmax]` _←_ `0` 5: `is_star[1,...,nt]` _←_ `false` 6: `num_edges_treated` _←_ 0 7: for _k_ = 1 to `nt` do 8: `queue_start` _←_ 1 9: `queue_end` _←_ 0 10: `first_vertex` _←_ `tree_edge_indices[k]` `+` `k` `-` `1` 11: `last_vertex` _←_ `tree_edge_indices[k` `+` `1]` `+` `k` `-` `1` 12: for `index_vertex` in `first_vertex:last_vertex` do 13: `vertex` _←_ `tree_vertices[index_vertex]` 14: `index_first_neighbor` = `tree_neighbor_indices[index_vertex]` 15: `degree` = `tree_neighbor_indices[index_vertex+1]` - `index_first_neighbor` 16: `degrees[vertex]` _←_ `degree` 17: `reverse_mapping[vertex]` _←_ `index_vertex` 18: if `degree` `==` 1 then 19: `queue_end` `+=` `1` 20: `queue[queue_end]` _←_ `vertex` 21: end if 22: end for 23: `nv_tree` _←_ `tree_edge_indices[k` `+` `1]` `-` `tree_edge_indices[k]` `+` `1` 24: `is_star[k]` _←_ `queue_end` _≥_ `nv_tree` `-` `1` 25: while `queue_start` _≤_ `queue_end` do 26: `leaf` _←_ `queue[queue_start]` 27: `queue_start` `+=` `1` 28: `degrees[leaf]` _←_ 0 29: `index_leaf` _←_ `reverse_mapping[leaf]` 30: `first_neighbor` _←_ `tree_neighbor_indices[index_leaf]` 31: `last_neighbor` _←_ `tree_neighbor_indices[index_leaf` `+` `1]` `-` `1` 32: for `index_neighbor` in `first_neighbor:last_neighbor` do 33: `neighbor` _←_ `tree_neighbors[index_neighbor]` 34: if `degrees[neighbor]` _̸_ = 0 then 35: `num_edges_treated` `+=` `1` 36: `reverse_bfs_orders[num_edges_treated]` _←_ ( `leaf`, `neighbor` ) 37: `degrees[neighbor]` `-=` `1` 38: if `degrees[neighbor]` `==` 1 then 39: `queue_end` `+=` `1` 40: `queue[queue_end]` _←_ `neighbor` 41: end if 42: end if 43: end for 44: end while 45: end for Algorithm C.7: Procedure the compute the reverse BFS order of the trees. [toc] Revisiting sparse matrix coloring and bicoloring 35 Input: _•_ `buckets` : a vector of stacks, one per degree _•_ `v` : a vertex to be moved up one degree 1: `d` _←_ current dynamic degree of `v` 2: `p` _←_ position of `v` inside `buckets[d]` 3: `w` _←_ `buckets[d][end]` 4: `buckets[d][p]` _←_ `w` 5: `buckets[d][end]` _←_ `v` 6: `pop_last(buckets[d])` 7: `append_last(buckets[d+1],` `v)` 8: record new positions of `v` and `w` Algorithm C.8: Stack-based degree bucket update, following `ColPack` . Input: _•_ `bucketvec` : a vector of integers, one per vertex _•_ `bucketlims` : a vector of integer pairs, one per degree _•_ `v` : a vertex to be moved up one degree 1: `d` _←_ current dynamic degree of `v` 2: `p` _←_ position of `v` inside `buckets[d]` 3: `(a,` `b)` _←_ `bucketlims[d]` 4: `(a_up,` `b_up)` _←_ `bucketlims[d+1]` 5: `w` _←_ `buckets[d][end]` 6: `bucketvec[a+p]` _←_ `w` 7: `bucketvec[a_up-1]` _←_ `v` 8: `bucketlims[d]` _←_ `(a,` `b-1)` 9: `bucketlims[d+1]` _←_ `(a_up-1,` `b_up)` 10: record new positions of `v` and `w` Algorithm C.9: Vector-based degree bucket update, introduced in `SMC` .

섹션 본문

섹션 본문이 없습니다.

참고문헌

참고문헌 정보가 없습니다.