Gaussian Elimination Function that is Fast

I was testing this package from this repository, it is faster than A \ b

I do not know any other competitor for calculating Gaussian Elimination that can be measured with @time. If anyone knows, I would like to know and do benchmark test on all of them.

This is from Julia REPL and JupyterNotebook:


A couple of suggestions: do not test with @time in the global scope. Use BenchmarkTools to test performance.
For instance

julia> b = rand(3)
3-element Vector{Float64}:
 8.30429e-01
 1.46162e-01
 8.75693e-02

julia> A = rand(3, 3)
3×3 Matrix{Float64}:
 2.81443e-01  1.72279e-01  4.03091e-01
 2.49288e-01  2.35197e-01  2.02405e-01
 2.82910e-01  8.54934e-01  9.42708e-01

julia> using BenchmarkTools

julia> @btime $A \ $b
  563.934 ns (3 allocations: 288 bytes)
3-element Vector{Float64}:
  1.46582e+00
 -2.88576e+00
  2.27007e+00

julia> 
2 Likes

Great suggestion, what is the different with this BenchmarkTools?

The result is the other way around now.

Capture d’écran_2022-07-24_21-14-14

You should take a look at the BenchmarkTools documentation, where it is explained why you should not use global variables when benchmarking. Note the dollar signs in @PetrKryslUCSD’s code. Also, it is nicer to provide example code and outputs in code blocks rather than using screen images. That way other people can copy and paste your examples.

1 Like

A couple more packages for you to look at: MKL and RecursiveFactorization.

1 Like

LAPACK, OpenBLAS, MKL etc are all optimized for large matrices. For a tiny matrix like 3x3 they introduce a lot of overhead and a simple loop will often be faster.

But if you have lots of tiny 3x3 systems it will be faster still to use StaticArrays, which can unroll and inline everything.

4 Likes

I try BenchmarkTools on finding a solution of a linear system and compare the time for two different methods in Julia:

A = [1 2 3;
     2 5 3;
     1 0 8]

b = [5; 3; 17]
using BenchmarkTools

@btime $A \ $b
@btime inv(A)*b

Capture d’écran_2022-07-25_19-14-16