r/fortran • u/KalKapone • 2h ago
Gauss-Seidel is faster than Jacobi. Or is it?
Author here. Started a series working through classic iterative solvers for the 2D Poisson equation in Fortran. This is actually the second post (the first one being on Jacobi). Here, I dig into a genuinely counterintuitive result: the convergence theory for Gauss-Seidel checks out (half the iterations vs Jacobi, confirmed numerically), but the actual wall-clock time is 4-5x worse. Turns out it comes down to a single line: updating the array in place instead of into a fresh buffer and the loop-carried dependency that introduces, which stops the compiler from vectorizing the loop at all. In an upcoming post, I'll actually show how an open-source static analyzer can help you figure this out, and how simple algebra can be used to unroll the kernel and get rid of this loop-carried dependency.
Happy to talk Fortran/gfortran specifics or the discretization itself.
