Skip to content

Conversation

@gdalle
Copy link
Contributor

@gdalle gdalle commented Jun 27, 2024

Add comparison between DifferentiationInterface and SparseDiffTools on the Brusselator Jacobian

Spoiler alert: for this very specific use case and AD backend the new pipeline is

  • 100x faster for sparsity detection
  • 10x faster for coloring
  • ten percent slower for the compressed differentiation itself (but I haven't even profiled the code so there is clearly room for improvement)

@gdalle
Copy link
Contributor Author

gdalle commented Jun 27, 2024

Results on my computer:

Sparse AD benchmarks.pdf

@ChrisRackauckas ChrisRackauckas marked this pull request as ready for review June 27, 2024 20:56
@ChrisRackauckas ChrisRackauckas merged commit 22de279 into master Jun 27, 2024
@ChrisRackauckas ChrisRackauckas deleted the gd/sparsead branch June 27, 2024 20:57
@ChrisRackauckas
Copy link
Member

Can you also add the caching PDE one?

using PreallocationTools

const cs = Val{ForwardDiff.pickchunksize(length(u))}
const Ayu = FixedSizeDiffCache(zeros(N, N), cs)
const uAx = FixedSizeDiffCache(zeros(N, N), cs)
const Du = FixedSizeDiffCache(zeros(N, N), cs)
const Ayv = FixedSizeDiffCache(zeros(N, N), cs)
const vAx = FixedSizeDiffCache(zeros(N, N), cs)
const Dv = FixedSizeDiffCache(zeros(N, N), cs)
function gm3!(dr, r, p, t)
    a, α, ubar, β, D1, D2 = p
    Ayu = get_tmp(Ayu, dr)
    uAx = get_tmp(uAx, dr)
    Du = get_tmp(Du, dr)
    Ayv = get_tmp(Ayv, dr)
    vAx = get_tmp(vAx, dr)
    Dv = get_tmp(Dv, dr)
    u = @view r[:, :, 1]
    v = @view r[:, :, 2]
    du = @view dr[:, :, 1]
    dv = @view dr[:, :, 2]
    mul!(Ayu, Ay, u)
    mul!(uAx, u, Ax)
    mul!(Ayv, Ay, v)
    mul!(vAx, v, Ax)
    @. Du = D1 * (Ayu + uAx)
    @. Dv = D2 * (Ayv + vAx)
    @. du = Du + a * u * u ./ v + ubar - α * u
    @. dv = Dv + a * u * u - β * v
end
f(du,u) = f(du,u,p,0.0)

version from https://docs.sciml.ai/DiffEqDocs/stable/tutorials/faster_ode_example/#Example-Accelerating-Linear-Algebra-PDE-Semi-Discretization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants