Skip to content

Compiletime for tensor very slow #278

Closed
@michel2323

Description

@michel2323

We do prototyping of a time integration using a handwritten residual function (50 lines) and Jacobian (100 lines):

    while norm_res > eps
        iteration = iteration + 1
        for iter in eachindex(J)
            J[iter]=0.0
        end
        jac_beuler(x, xold, h, e_fd, p_m, J, Ymat)
        x = x - inv(J)*F
        residual_beuler(x, xold, h, e_fd, p_m, F, Ymat)
        norm_res = norm(F)
    end

Computing the Jacobian, Hessian and tensor of one timestep with

    jac_cfg = ForwardDiff.JacobianConfig(integrate_wrapper, x, ForwardDiff.Chunk{1}())
    jac = x -> ForwardDiff.jacobian(integrate_wrapper, x, jac_cfg)
    
    hes_jac = x -> ForwardDiff.jacobian(integrate_wrapper, x)
    hes_cfg = ForwardDiff.JacobianConfig(hes_jac, x, ForwardDiff.Chunk{1}())
    hes = x -> ForwardDiff.jacobian(hes_jac, x, hes_cfg)

    ten_hes = x -> ForwardDiff.jacobian(hes_jac, x)
    ten_cfg = ForwardDiff.JacobianConfig(ten_hes, x, ForwardDiff.Chunk{1}())
    ten = x -> ForwardDiff.jacobian(ten_hes, x, ten_cfg)

results in the following runtime:

  1st Jacobian: 2.629844 seconds (1.13 M allocations: 49.980 MiB, 1.57% gc time)
  2nd Jacobian 0.005359 seconds (14.67 k allocations: 751.859 KiB)
  1st Hessian 26.822772 seconds (20.38 M allocations: 625.502 MiB, 2.31% gc time)
  2nd Hessian 0.151826 seconds (58.35 k allocations: 11.634 MiB, 22.91% gc time)
  1st tensor 6536.218095 seconds (12.29 G allocations: 319.796 GiB, 2.90% gc time)

I already profiled and typed the code as much as possible I could. This is run with Julia -O0. With these JIT compilation times I would be happy to sacrifice a bit of runtime for a faster JIT.

Is there any way to reduce the time for the tensor?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions