betaFeedback

WorksPhysics and Astronomy

Optimized solver algorithms for computing Tr(A−1)\mathrm{Tr}(A^{-1})

Abstract

Estimating the trace of the inverse of a large quark matrix is a longstanding problem in lattice QCD. The standard approach is Hutchinson's method, which uses random noise vectors to estimate the trace to a desired statistical tolerance. Each noise vector bb requires solving a system of linear equations Ax=bAx = b. In this work, we introduce a new class of Krylov solvers for this task, called Twin methods. Twin methods generate the Krylov polynomial once then reuse it on all other right-hand sides. This reduces the number of basic linear algebra operations in the algorithm and therefore lowers the trace computation time. We apply the Twin approach to BiCG and BiCGStab and test them on lattice QCD matrices of varying size and in a range of computing contexts. We also present a more economical estimation of Tr(A−1)\mathrm{Tr}(A^{-1}) which implements a polynomial approximation of A−1A^{-1} and a singular value deflation. In this scheme, the solvers are applied to only a few noise vectors, and the remainder are treated by the polynomial and the deflation. In our tests, the polynomial approximation combined with the deflation yield a 17-fold speedup in the time required to compute the trace over standard Hutchinson's method.

Introduction

A longstanding problem in lattice QCD is computing the trace of the inverse Wilson-Dirac operator, Tr⁡(A−1)\operatorname{Tr}(A^{-1}), which corresponds to the fermionic contraction of the scalar density operator, ψˉψ\bar{\psi}\psi, on the lattice. Because computing A−1A^{-1} directly is prohibitively expensive, the trace is estimated stochastically. The standard approach is Hutchinson’s method [1],

Tr⁡(A−1)≈1N∑i=1Nbi†A−1bi=1N∑i=1Nbi†xi,(1)\operatorname{Tr}(A^{-1}) \approx\frac{1}{N}\sum_{i=1}^{N} b_i^{\dagger} A^{-1} b_i = \frac{1}{N}\sum_{i=1}^{N} b_i^{\dagger} x_i, \tag*{(1)}

where the bib_i are isotropic random noise vectors and xi=A−1bix_i = A^{-1}b_i is the solution to the system of linear equations Axi=biAx_i = b_i. In practice, NN is not fixed but is determined by the number of noise vectors required to reach a desired standard-error tolerance.

There are many algorithms for solving large systems of linear equations, including BiCG and BiCGStab in addition to more sophisticated methods. In § 2 we introduce a new class of Krylov solvers for efficiently solving multiple RHSs, which we call “Twin” methods. A Twin method solves the first RHS using a standard Krylov solver then reuses the Krylov polynomial on all subsequent RHSs. This approach significantly reduces the number of basic linear algebra operations that contribute to the cost of the problem.

This paper applies the Twin method to BiCG and BiCGStab and compares them with standard BiCGStab and BiCG-QCD (BiCG exploiting the QCD γ5\gamma^5 symmetry). In § 3, we present tests on various QCD matrices and interpret the results. § 4 discusses a more elaborate evaluation of the trace using a polynomial approximation of A−1A^{-1} and a singular value deflation, which reduces the computational expense.

Algorithms

The algorithms we use in this work are BiCGStab [2], BiCG-QCD [3], Twin BiCG, and Twin BiCGStab. Table 1 summarizes the basic features of the first three methods. We first present the theoretical basis for Twin Krylov methods (§ 2.1) and then discuss their benefits over independent, sequential Krylov solvers (§ 2.2).

MethodBiCGStabBiCG-QCDTwin BiCGTwin BiCGStab
MVPs/iteration211*2*
DPs/iteration210*0*
Multiple solvesindependentindependentreuse π\pi polynomialreuse π\pi polynomial

Table 1. Solver characteristics. Asterisks indicate costs after the base solve.

Twin Krylov methods

To motivate Twin Krylov methods, we first review the convergence of a general Krylov method. To begin, note that the approximate solution x^\hat{x} to Ax=bAx = b is extracted from the Krylov subspace,

x^∈Km(b,A)=span⁡{b,Ab,A2b,…,Am−1b}.(2)\hat{x} \in K^m(b,A) = \operatorname{span}\{b, Ab, A^2b, \ldots, A^{m-1}b\}. \tag*{(2)}

Thus x^=p(A)b\hat{x}=p(A)b for some polynomial p(A)p(A) of degree m−1m-1 or less, and the residual is

r=b−Ax^=π(A)b,(3)r=b-A\hat{x}=\pi(A)b, \tag*{(3)}

where π(A)=I−Ap(A)\pi(A)=I-Ap(A) is the residual polynomial. Let {λi,zi}\{\lambda_i,z_i\} be the orthonormal eigenbasis of the n×nn \times n matrix AA and expand b=∑icizib=\sum_i c_i z_i. Then

π(A)b=π(A)(c1z1+⋯+cnzn)(4)\pi(A)b=\pi(A)(c_1z_1+\cdots+c_nz_n) \tag*{(4)}
=c1π(λ1)z1+⋯+cnπ(λn)zn.(5)=c_1\pi(\lambda_1)z_1+\cdots+c_n\pi(\lambda_n)z_n. \tag*{(5)}

The residual is therefore small when π(λi)\pi(\lambda_i) is small along the whole spectrum of AA, at least for the eigenvectors that bb has substantial weight on.

The Twin method for multiple RHSs relies on the following observation: π\pi is determined by the part of the spectrum of AA where the first RHS has weight, and a π\pi that is small along the eigencomponents of one RHS will also be small along the shared eigencomponents of any other RHS. Since the random vectors are isotropic, E[bb†]=1\mathbb{E}[bb^\dagger]=1, and the eigenbasis is orthonormal, then the eigencomponents are uniformly distributed for each noise, E[∥ci∥2]=1\mathbb{E}[\lVert c_i\rVert^2]=1. Hence, even though π\pi is generated using a particular noise, it does not statistically favor that noise and may be applied unbiasedly to other RHSs.2

In practice, this amounts to saving the recurrence coefficients generated on the first solve and reusing them on the next solves. Alg. 1 shows the Twin approach applied to BiCG, which we call Twin BiCG.

Algorithm 1 Twin BiCG (for multiple RHSs)

  1. Solve the first RHS using standard BiCG and save the parameters {αi}\{\alpha_i\} and {βi}\{\beta_i\}. For all subsequent RHSs:

  2. Compute r0=b−Ax0r_0=b-Ax_0. Choose r0′r'_0 such that r0′†r0≠0{r'_0}^{\dagger}r_0\ne0.

  3. Set, p0=r0p_0=r_0, p0′=r0′p'_0=r'_0.

  4. for j=0,1,…,mj=0,1,\ldots,m do

  5. xj+1=xj+αjpjx_{j+1}=x_j+\alpha_jp_j

  6. rj+1=rj−αjApjr_{j+1}=r_j-\alpha_jAp_j

  7. pj+1=rj+1+βjpjp_{j+1}=r_{j+1}+\beta_jp_j

  8. end for

Benefits of Twin algorithms

Beyond the first solve, Twin BiCG halves the number of matrix-vector products (MVPs) relative to standard BiCG and both Twin BiCG and Twin BiCGStab eliminate dot products entirely. The latter matters for large scale problems on distributed memory where the relative cost of a dot product is very high due to the overhead cost to transfer the information.

Twin methods also adapt easily to a batched solve context where multiple RHSs are solved simultaneously as AX=BAX=B, where B=[b1⋯bm]B=[b_1\cdots b_m] for mm RHSs, and XX contains the corresponding solutions. Batching replaces matrix-vector operations with matrix-matrix operations, which reuse data more efficiently. Because the coefficients are shared, each column of BB requires the same number of iterations and therefore the noise vectors converge together. This simplifies the implementation compared to other batched Krylov solvers which require a different number of iterations for each column in BB.

Furthermore, Twin methods can prevent convergence failures in systems that are prone to them. Suppose standard BiCGStab fails on one in four noise vectors, meaning no usable π\pi is generated. Twin BiCGStab avoids this since the parameters are saved from the first successful RHS and reused on all others, including those that would otherwise fail under standard BiCGStab. In § 3 we will see several instances where standard BiCGStab experiences convergence failures on noise vectors for which Twin BiCGStab does not.

Hutchinson’s Method Tests

Tests were performed on QCD matrices from three ensembles. In § 3.1, matrices labeled “H” come from a 123×1612^3 \times16 quenched lattice, with Wilson fermions at the critical hopping parameter κc=0.157\kappa_c = 0.157. In § 3.2 and § 3.3, we use gauge configurations from the MILC Collaboration’s Nf=2+1+1N_f = 2 + 1 + 1 Highly Improved Staggered Quark (HISQ) program [4], generated with a one-loop Symanzik-improved gauge action and HISQ dynamical sea quarks. Ensemble “A” is 163×4816^3 \times48 with light quark mass ml,A=16.9m_{l,A} = 16.9 MeV, and ensemble “B” is 243×6424^3 \times64 with ml,B=8.26m_{l,B} = 8.26 MeV. Wilson fermion matrices are built on these configurations with hopping parameters corresponding to the physical pion mass: κA=0.1708\kappa_A = 0.1708 and κB=0.1657\kappa_B = 0.1657. The GPU tests in § 3.2 onward were run on the Delta cluster using NVIDIA A100 GPUs.

Single thread benchmark comparison

We begin by comparing the computational cost of Twin BiCG to BiCGStab using minimal computer resources. The tests were run on the H matrices and utilized a single Delta CPU core and 128 Gb of RAM. In MATLAB, the number of computational threads was restricted to one since multiple threads are used by default. This isolates the benefits of algorithm design from those of hardware parallelism.

The test results are displayed in Figure 1. For matrices H02, H05, H06, and H07, Twin BiCG was substantially faster because several BiCGStab solves failed to converge, which significantly increased the total time. Twin BiCG avoids this since π\pi is reused from a successful solve. For matrices H01, H04, H09, and H10, both methods finished in comparable and relatively short times. Twin BiCG often requires more iterations per solve, but each iteration is cheaper because it needs fewer MVPs and no dot products beyond the first solve, so the two effects roughly offset. Twin BiCG is therefore competitive with BiCGStab when BiCGStab converges and substantially more robust when it does not.

Trace times comparing BiCGStab and Twin BiCG on a single computational thread for the H matrices

Figure 1. Trace times comparing BiCGStab and Twin BiCG on a single computational thread for the H matrices (123×1612^3 \times16). The relative solve tolerance is 10−310^{-3} and the trace tolerance is 123×16×0.00112^3 \times16 \times0.001.

A matrices

Now we present GPU tests on the A matrices. We compare four methods: Twin BiCG, Twin BiCGStab, BiCGStab and BiCG-QCD, where the last two methods serve as benchmarks. The times required to compute the trace on a set of ten different matrices are presented in Figure 2.

Figure 2. Trace times for the A matrices (163×4816^3 \times48) using BiCGStab, BiCG-QCD, Twin BiCG, and Twin BiCGStab. The relative solve tolerance is 10−310^{-3} and the trace tolerance is 0.001×163×480.001 \times16^3 \times48.

BiCGStab fails on 54% and 86% of noise vectors for matrices A9020 and A9025, respectively, compared to 0% for all other matrices in the test set. This difficulty may be attributed to the presence of negative eigenvalues in their spectra, while the spectra of the other matrices lie in the right-half plane.3 Twin BiCGStab circumvents this problem by reusing a successful π\pi polynomial on noise vectors that would otherwise fail to converge under standard BiCGStab. As a result, it was faster than BiCGStab by factors of 6.8 and 11.5 on matrices A9020 and A9025, respectively.

Matrices A9020, A9025, and A9045 are the only instances where Twin BiCGStab is slower than Twin BiCG. For A9025, this is partly due to the first 15 noise vectors, all of which failed to converge. Until a successful solve occurs, there is no π\pi to reuse, so each noise vector is a full solve attempt. Many of these attempts ran the maximum number of solve iterations before terminating, and each iteration of Twin BiCGStab costs two MVPs, so they contribute a significant share of the total trace time.

The iteration count associated with each solve also matters. Let rr be the ratio of the number of iterations per noise vector for Twin BiCGStab to that for Twin BiCG. For A9020, A9025, and A9045, r=0.93r = 0.93, 1.32, and 0.76, respectively. For all other matrices rr averaged 0.48—roughly half as many iterations for Twin BiCGStab compared to Twin BiCG. Because each iteration of Twin BiCGStab requires two MVPs whereas Twin BiCG only requires one, Twin BiCGStab is only faster when rr is sufficiently small; the relatively large values of rr on these matrices help explain the larger times. In short, although Twin BiCGStab is generally faster and more robust that BiCGStab, its cost is dominated by the number of iterations needed for the first successful solve, which is determined by the underlying BiCGStab algorithm.

The average times across the matrices for each method are shown on the right of Figure 2. Because estimating the trace across an entire ensemble requires solving on every configuration, this average is the most important metric. On this measure, Twin BiCGStab is the fastest method and standard BiCGStab is the slowest, which demonstrates the benefit of recycling the π\pi polynomial.

In addition to the runs in Figure 2, tests were also done in a batched format. The total number of noise vectors required for the trace is not known in advance, but because the error scales as 1/n1/\sqrt{n}, one may estimate the number of noise vectors from the first batch, and the next batches are sized accordingly. (However, the size of the first batch is an a priori heuristic guess.) The benefit of batching is that serial matrix-vector operations are replaced with matrix-matrix operations which reuse data more efficiently, reducing the trace time without compromising the accuracy of the trace estimate.

The results in Figure 3 include batched methods. They are consistent with the relative ranking of the results in Figure 2. In every test, batching of a method made it faster than its non-batched counterpart. This is expected since batching just changes how the operations are executed, not the algorithm structure. These results suggest that batching is always preferable to serial solves when memory permits. Table 2 gives the speedup of each method relative to the slowest, standard BiCGStab.

Trace times for the A matrices

Figure 3. Trace times for the A matrices (163×4816^3 \times48) using Twin BiCG, Twin BiCGStab, Twin BiCG Batch, and Twin BiCGStab Batch. The relative solve tolerance is 10−310^{-3} and the trace tolerance is 0.001×163×480.001 \times16^3 \times48.

SolverA speedupB speedup
BiCGStab1.001.00
Twin BiCG4.471.82
Twin BiCGStab5.221.84
BiCG-QCD2.911.25
Twin BiCG Batch7.00
Twin BiCGStab Batch8.21

Table 2. Speedup factor for Hutchinson’s method using different solvers compared to the slowest average solver, BiCGStab. Batched tests were not performed for B matrices.

B matrices

We now present GPU tests on the larger B matrices. The results are shown in Figure 4. Unlike the set of A matrices, BiCGStab was faster than both BiCG-QCD and Twin BiCG on most B matrices. The exceptions were B5000 and B5020, on which BiCGStab failed to converge on 14.3% and 28.9% of noise vectors, respectively. These failures were costly enough that BiCGStab had the longest average wall-clock time of all the methods. As with the A matrices, Twin BiCG and

Trace times for the B matrices using BiCGStab, BiCG-QCD, Twin BiCG, and Twin BiCGStab

Figure 4. Trace times for the B matrices (243×6424^3 \times64) using BiCGStab, BiCG-QCD, Twin BiCG, and Twin BiCGStab. The relative solve tolerance is 10−310^{-3} and the trace tolerance is 0.0005×243×640.0005 \times24^3 \times64.

Twin BiCGStab are the fastest average methods because they avoid repeated failures by reusing a successful π\pi polynomial rather than solving each noise vector independently.

Singular Value Deflation and Polynomial Subtraction

The costs of the trace estimation can be reduced by subtracting a polynomial approximation of A−1A^{-1} [5]. The trace may be written as

Tr⁡(A−1)=Tr⁡(A−1−p(A))+Tr⁡(p(A)),(6)\operatorname{Tr}(A^{-1}) = \operatorname{Tr}(A^{-1} - p(A)) + \operatorname{Tr}(p(A)), \tag*{(6)}

where p(A)≈A−1p(A) \approx A^{-1}.4 The degree of the polynomial must be high so that very few noise vectors are required to compute the first trace in the sum, Tr⁡(A−1−p(A))\operatorname{Tr}(A^{-1} - p(A)). Costs can be further reduced by including a singular value deflation in Eq. (6). The idea of deflating eigenvalues and singular values from a QCD Monte Carlo started with [6], followed by [7] in which singular value deflation is called “Hermitian forced eigenvalue subtraction” (but there are some errors). The full trace is

Tr⁡(A−1)≈Tr⁡(A−1−p(A))+Tr⁡(p(A)−∑i1σiviui†)+Tr⁡(∑i1σiviui†),(7)\operatorname{Tr}(A^{-1}) \approx\operatorname{Tr}(A^{-1} - p(A)) + \operatorname{Tr}\left(p(A) - \sum_i \frac{1}{\sigma_i}v_i u_i^\dagger\right) + \operatorname{Tr}\left(\sum_i \frac{1}{\sigma_i}v_i u_i^\dagger\right), \tag*{(7)}

where {1/σi}\{1/\sigma_i\} are the smallest singular values of A−1A^{-1}, and {vi}\{v_i\} and {ui}\{u_i\} are the left and right singular values of A−1A^{-1}, respectively.5 The number of noise vectors needed for the second trace in Eq. (7) will be reduced from the number required for the second trace in Eq. (6) since the problematic singular modes are deflated out. Trace three of Eq. (7) can be computed exactly, so it will not contribute any error in the estimation.

Testing

The polynomial subtracted (PS) trace (Eq. (6)) and the full polynomial subtracted and singular value deflated (PS+SVD) trace (Eq. (7)) were tested on a 24424^4 quenched lattice with Wilson fermions at the critical hopping parameter, κ=κc=0.157\kappa= \kappa_c = 0.157, using NVIDIA A100 GPUs. The fermion matrices associated with this lattice are labeled with a “J” and the wall-clock times to compute the trace using the PS and PS+SVD methods are shown in Figure 5. These times are compared to standard Hutchinson’s method using BiCGStab.

Trace times for the J matrices

Figure 5. Trace times for the J matrices (24424^4) using Hutchinson’s method, the PS trace, and the PS+SVD trace. Traditional Hutchinson’s method is solved using BiCGStab with a relative solve tolerance of 10−510^{-5}. The trace tolerance is 0.0005 × 24424^4.

On average, PS alone is 3.52 times faster than Hutchinson’s method, and adding the deflation raises the speedup to 17.0 (see Table 3). The individual matrices show how PS and SVD contribute different effects. PS reduces the time by a roughly constant factor, so matrices that are slow under Hutchinson are still relatively slow under PS. Deflation, by removing the smallest singular values that make the solves difficult, makes the times similar across the matrices.

Hutch/PSPS/(SVD+PS)Hutch/(SVD+PS)
Speedup factor3.524.8217.01

Table 3. Speedup factor when comparing Hutchinson’s method (Hutch), the single polynomial subtraction method of Eq. (6) (PS), and the full polynomial subtracted and singular value deflated method of Eq. (7) (SVD+PS).

Computing the singular values used in the deflation accounts for only 11% of the overall PS+SVD trace time on average, which is included in the times reported in Figure 5. The number of singular values deflated was not fixed in advance and cannot be easily predicted. This does not appear to be a practical obstacle provided enough of the singular modes are deflated to reduce the overall difficulty of the problem.

Conclusions

We first introduced a new class of Krylov solvers called Twin methods for solving multiple RHSs. We then used Twin BiCG and Twin BiCGStab to compute Tr⁡(A−1)\operatorname{Tr}(A^{-1}) with Hutchinson’s method on several different semi-quenched lattice QCD matrices from two MILC ensembles. Ensemble A was a 163×4816^3 \times48 lattice and B was a 243×6424^3 \times64 lattice; the kappa values associated with the physical pion mass were used. Twin BiCG and Twin BiCGStab were especially beneficial on matrices where standard solvers failed on a large fraction of noise vectors, since the Twin methods reuse the π\pi polynomial from a successful solve and so avoid repeated failures. Batching noises further improved the trace times because matrix-matrix operations reuse data more efficiently than matrix-vector operations. On the A matrices, Twin BiCGStab was 8.21 times faster than the slowest method, standard BiCGStab. We then introduced a polynomial subtraction and a singular value deflation to the trace. For these tests we used a 24424^4 quenched lattice set to κ\kappa-critical. The PS+SVD method gave a 17-fold speedup over standard Hutchinson’s method and made the cost far less dependent on the individual matrix.

Acknowledgements

We are grateful to the MILC collaboration for sharing the lattices used in this work. This work was supported in part through allocation MTH250023 from the NSF ACCESS program.

References

  1. [1]M. F. Hutchinson. A stochastic estimator of the trace of the influence matrix for Laplacian smoothing splines. Commun. Stat. Simul. Comput., 18:1059–1076, 1989.
  2. [2]H. A. van der Vorst. Bi-CGSTAB: A fast and smoothly converging variant of Bi-CG for the solution of nonsymmetric linear systems. SIAM J. Sci. Stat. Comput., 13:631–644, 1992.
  3. [3]Andreas Frommer, Bertold Nöckel, Stephan Gü̈sken, Thomas Lippert, and Klaus Schilling. Many masses on one stroke: Economic computation of quark propagators. International Journal of Modern Physics C, 06(05):627–638, October 1995.DOI
  4. [4]A. Bazavov, C. Bernard, J. Komijani, C. DeTar, L. Levkova, W. Freeman, Steven Gottlieb, Ran Zhou, U. M. Heller, J. E. Hetrick, J. Laiho, J. Osborn, R. L. Sugar, D. Toussaint, and R. S. Van de Water. Lattice qcd ensembles with four flavors of highly improved staggered quarks. Phys. Rev. D, 87:054505, Mar 2013.
  5. [5]P. Lashomb, R. B. Morgan, T. Whyte, and W. Wilcox. Multi-polynomial Monte Carlo for QCD trace estimation. Comput. Phys. Commun., 300:109163–1 – 109163–10, 2024.arxiv.org/abs/2306.09559
  6. [6]V. Guerrero, R. B. Morgan, and W. Wilcox. Eigenspectrum noise subtraction methods in lattice QCD. Proceedings of Science, LAT2009, pages 041/1–041/8, 2009.arxiv.org/abs/1001.4366
  7. [7]V. Guerrero. Electric neutron polarizability and eigenspectrum subtraction techniques for disconnected quark loops. PhD Thesis, Baylor University, 2011.

Paper details

vlnc:W_rd4ntvh8
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 5

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Physics and Astronomy

Not recorded for this paper

View statement
Looking for related papers…
Contents