# 三对角矩阵算法

三对角矩阵算法，又称Thomas算法，是高斯消元法的一种简化形式，用于求解系数矩阵为三对角矩阵的线性方程组——所谓三对角，即非零元素只出现在主对角线及与之相邻的两条对角线上。<sup>[1](https://mathworld.wolfram.com/ThomasAlgorithm.html)</sup> 此类方程组在科学与工程中不断出现，尤其当一维偏微分方程用有限差分方法离散化时，因为此时每个变量只依赖于它的直接邻居。<sup>[2](https://pdtyreus.github.io/numerical_methods/tridiagonal_solvers.html)</sup> Thomas算法的求解时间与行数成正比，但它本质上是串行的，因此人们又发展了循环归约、并行循环归约等并行方法，用于多核与GPU平台。<sup>[3](https://www.researchgate.net/publication/235606124_Selecting_the_Best_Tridiagonal_System_Solver_Projected_on_Multi-Core_CPU_and_GPU_Platforms)</sup>

| 关键事实 | 详情 |
|---|---|
| 方法 | 针对三对角系统的专门化高斯消元，即先做LR分解，再作前代与回代<sup>[1](https://mathworld.wolfram.com/ThomasAlgorithm.html)</sup><sup> • </sup><sup>[4](https://www-sop.inria.fr/asclepios/Publications/Stefanescu/thesis_stefanescu.pdf)</sup> |
| 代价 | 总的乘除法次数远少于稠密高斯消元加回代所需的约\( n^{3}/3 \)次运算<sup>[5](https://archive.nptel.ac.in/content/storage2/courses/103101009/modules/module4/sec4/1.4.html)</sup> |
| 稳定性条件 | 当某个消元分母为零，或小到无法进行稳定的浮点计算时，需要选主元或改用更一般的求解器<sup>[1](https://mathworld.wolfram.com/ThomasAlgorithm.html)</sup> |
| 并行替代方案 | 循环归约（CR）、并行循环归约（PCR）与递归倍增（RD）可开发细粒度并行性<sup>[3](https://www.researchgate.net/publication/235606124_Selecting_the_Best_Tridiagonal_System_Solver_Projected_on_Multi-Core_CPU_and_GPU_Platforms)</sup><sup> • </sup><sup>[6](https://research.nvidia.com/sites/default/files/pubs/2010-01_Fast-Tridiagonal-Solvers/Zhang_Fast_2009.pdf)</sup> |
| GPU性能 | 混合CR+PCR与CR+RD分别比PCR、RD、CR快21%、31%和61%；GPU求解器相比串行LAPACK最高可达28倍加速<sup>[6](https://research.nvidia.com/sites/default/files/pubs/2010-01_Fast-Tridiagonal-Solvers/Zhang_Fast_2009.pdf)</sup> |
| 典型用途 | 热传导方程等一维偏微分方程的隐式时间推进，以及CFD代码中的光滑化步骤<sup>[2](https://pdtyreus.github.io/numerical_methods/tridiagonal_solvers.html)</sup><sup> • </sup><sup>[7](https://escholarship.org/uc/item/9hv9327j)</sup> |

## Thomas算法

Thomas算法的工作方式是符号化地消去三对角矩阵的次对角线元素，从而构造出一个单位下三角矩阵\( L \)和一个上三角矩阵\( U \)，后者的对角元素\( \{u_i\}_{i=1}^{n} \)与超对角线元素均承自原矩阵；随后通过前代与回代求解方程组。由于消元只涉及三条对角线，总的乘除法次数显著少于对同规模稠密矩阵施行高斯消元加回代所需的约\( n^{3}/3 \)次运算。<sup>[5](https://archive.nptel.ac.in/content/storage2/courses/103101009/modules/module4/sec4/1.4.html)</sup>

**稳定性。** 消元过程可能在数值上失效。当某个消元分母为零，或小到无法进行稳定的浮点计算时，就需要选主元——即交换方程以避免零主元或过小的主元——或者改用更一般的求解器；奇异三对角矩阵便是会出现这种情况的一类情形。<sup>[1](https://mathworld.wolfram.com/ThomasAlgorithm.html)</sup><sup> • </sup><sup>[8](https://sites.nd.edu/gfu/files/2019/10/ms6021_thomas.pdf)</sup> 该算法应用于对角占优的方程组，正是在这一情形下，数值方法课程将其描述为快速而可靠。<sup>[8](https://sites.nd.edu/gfu/files/2019/10/ms6021_thomas.pdf)</sup>

## 三对角系统的来源

当一维问题被离散化时，所得的线性系统往往具有三对角结构，因为每个变量只依赖于它的直接邻居。<sup>[2](https://pdtyreus.github.io/numerical_methods/tridiagonal_solvers.html)</sup> 一个标准例子是隐式时间推进格式，例如对扩散方程应用隐式欧拉法，它会在每个时间步产生一个待求解的三对角系统。<sup>[9](https://doi.org/10.1016/J.JPDC.2018.01.004)</sup> 在计算流体力学中，三对角求解器被用作更庞大求解流程中的光滑化算法。<sup>[7](https://escholarship.org/uc/item/9hv9327j)</sup> 同样的结构也出现在图像处理应用中。<sup>[9](https://doi.org/10.1016/J.JPDC.2018.01.004)</sup>

## 并行求解器

Thomas算法不适合并行实现，因此人们发展了循环归约、递归倍增等算法来开发细粒度并行性。<sup>[3](https://www.researchgate.net/publication/235606124_Selecting_the_Best_Tridiagonal_System_Solver_Projected_on_Multi-Core_CPU_and_GPU_Platforms)</sup> 循环归约在系统规模\( n \)上是线性时间的，但其串行形式只具有O(1)的并行度；在每一个归约步中，当前系统被分裂为两个线性无关的子系统。<sup>[7](https://escholarship.org/uc/item/9hv9327j)</sup> 对行数为\( n \)的分块三对角矩阵，三种主要算法的比较展示了各自的取舍：<sup>[7](https://escholarship.org/uc/item/9hv9327j)</sup>

- **Thomas算法（TA）**：\( n \)步，总工作量正比于\( n m^{3} \)，并行度为1。
- **循环归约（CR）**：\( \log_{2} n \)步，每步工作量\( n/2 \)，总工作量正比于\( n m^{3} \)，并行度为\( n/2k \)。
- **并行循环归约（PCR）**：\( \log_{2} n \)步，每步工作量\( n \)，因此总工作量增至原来的\( \log_{2} n \)倍，当\( n \)较大时可能抵消并行度的提升。<sup>[7](https://escholarship.org/uc/item/9hv9327j)</sup>

**GPU求解器。** Zhang、Cohen与Owens在对CR、PCR与递归倍增的GPU研究中观察到：CR虽然算法复杂度是线性的，但算法步数较多，且会遇到存储体冲突；而PCR与RD步数较少，但每步的工作量更大。他们提出的混合CR+PCR与CR+RD算法分别比PCR、RD、CR快21%、31%和61%；在GPU上运行时，其求解器比串行LAPACK求解器快达28倍，比使用多线程的CPU求解器快12倍。<sup>[6](https://research.nvidia.com/sites/default/files/pubs/2010-01_Fast-Tridiagonal-Solvers/Zhang_Fast_2009.pdf)</sup>

**如何选择求解器。** 最佳算法取决于平台与系统规模。在一项跨多核CPU与GPU平台的比较中，对于\( 2^{22} \)个方程的大规模系统，多核CPU上最佳结果来自Bondeli算法，加速比为1.55倍，性能为0.84 GFLOPS；而GPU上循环归约表现最佳，加速比为17.06倍，性能为5.09 GFLOPS。<sup>[3](https://www.researchgate.net/publication/235606124_Selecting_the_Best_Tridiagonal_System_Solver_Projected_on_Multi-Core_CPU_and_GPU_Platforms)</sup> 在一项Python基准测试中，循环归约的Numba实现即使单核运行，一旦系统规模超过\( 10^{4} \)行，也胜过了基于LAPACK的行业标准SciPy求解器。<sup>[2](https://pdtyreus.github.io/numerical_methods/tridiagonal_solvers.html)</sup> 当需要同时求解大量相互独立的三对角系统时，系统数量本身即提供了并行性，此时在Thomas、CR与PCR之间作选择，需重新审视，并注意尽量减少与主存储器之间的数据传输。<sup>[10](https://ora.ox.ac.uk/objects/uuid%3A6985082c-8c58-4549-bfb8-6051b72b1fdc)</sup>

## 扩展

基本算法可以推广到标量系统之外。它们同样适用于标量与分块三对角系统，后者的每个矩阵元素本身就是一个秩为\( m \)的小矩阵。<sup>[7](https://escholarship.org/uc/item/9hv9327j)</sup> 对于可分离的分块三对角系统，循环归约的部分解变体（PSCR）是一种直接求解器；一项基于基-4的GPU实现被发现在利用GPU并行计算资源方面，优于所考虑的其他分块循环归约类方法。<sup>[9](https://doi.org/10.1016/J.JPDC.2018.01.004)</sup> 循环归约与SPIKE等算法将单个大型三对角系统化为多个小型独立系统并行求解，二者均已在开放计算语言中实现，适用于现场可编程门阵列、图形处理器及其他多核处理器等异构环境。<sup>[11](https://journal.austms.org.au/ojs/index.php/ANZIAMJ/article/view/9371)</sup> 对于三对角Toeplitz系统——其各条对角线为常数——GPU加速计算机上的专门并行算法可利用这一额外结构。<sup>[12](https://onlinelibrary.wiley.com/doi/abs/10.1002/cpe.6449)</sup>

## References

1. [Thomas Algorithm, Wolfram MathWorld](https://mathworld.wolfram.com/ThomasAlgorithm.html)
2. [Efficiently Solving Equations with Tridiagonal Matrices, P. Daniel Tyreus](https://pdtyreus.github.io/numerical_methods/tridiagonal_solvers.html)
3. [Selecting the Best Tridiagonal System Solver Projected on Multi-Core CPU and GPU Platforms](https://www.researchgate.net/publication/235606124_Selecting_the_Best_Tridiagonal_System_Solver_Projected_on_Multi-Core_CPU_and_GPU_Platforms)
4. [Stefanescu, thesis, Inria](https://www-sop.inria.fr/asclepios/Publications/Stefanescu/thesis_stefanescu.pdf)
5. [NPTEL, Thomas Algorithm for Tridiagonal and Block Tridiagonal Matrices](https://archive.nptel.ac.in/content/storage2/courses/103101009/modules/module4/sec4/1.4.html)
6. [Zhang, Cohen, Owens, Fast Tridiagonal Solvers on the GPU](https://research.nvidia.com/sites/default/files/pubs/2010-01_Fast-Tridiagonal-Solvers/Zhang_Fast_2009.pdf)
7. [GPGPU parallel algorithms for structured-grid CFD codes, eScholarship](https://escholarship.org/uc/item/9hv9327j)
8. [Tridiagonal Matrices: Thomas Algorithm, University of Notre Dame](https://sites.nd.edu/gfu/files/2019/10/ms6021_thomas.pdf)
9. [On solving separable block tridiagonal linear systems using a GPU implementation of radix-4 PSCR method, Journal of Parallel and Distributed Computing](https://doi.org/10.1016/J.JPDC.2018.01.004)
10. [Manycore algorithms for batch scalar and block tridiagonal solvers, Oxford University Research Archive](https://ora.ox.ac.uk/objects/uuid%3A6985082c-8c58-4549-bfb8-6051b72b1fdc)
11. [Implementation of parallel tridiagonal solvers for a heterogeneous computing environment, ANZIAM Journal](https://journal.austms.org.au/ojs/index.php/ANZIAMJ/article/view/9371)
12. [Solving tridiagonal Toeplitz systems of linear equations on GPU-accelerated computers, Concurrency and Computation](https://onlinelibrary.wiley.com/doi/abs/10.1002/cpe.6449)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Linear and multilinear algebra › Numerical linear algebra › Direct solvers for linear systems

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/tridiagonal-matrix-algorithm

English original: https://www.edgepedia.org/tridiagonal-matrix-algorithm
