# Matrix-free linear solvers for DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/matrix-free-linear-solvers-for-differentialequations-jl/10968>\
**Category:** Modelling & Simulations\
**Created:** [May 17, 2018, 9:31pm UTC](https://discourse.julialang.org/t/matrix-free-linear-solvers-for-differentialequations-jl/10968 "2018-05-17T21:31:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [May 17, 2018, 9:31pm UTC](https://discourse.julialang.org/t/matrix-free-linear-solvers-for-differentialequations-jl/10968/1 "2018-05-17T21:31:51Z")

</div>

I’m trying to solve a DAE (mass matrix form) for a 2D spectral discretization. The number of DOF is going to be large, and the Jacobian, which I compute explicitly, is not especially sparse.

I’d like to use a preconditioned Krylov solver operating in a matrix-free mode, as applying the Jacobian can be done much faster than the equivalent matrix-vector multiplication. But I can’t figure out how to do that within DifferentialEquations.jl.

Going by the docs, the linsolve option to the native Julia stiff solvers apparently expects to pass matrices around. In SUNDIALS, which does support “ATimes” functions instead of matrices for its iterative solvers, I can’t figure out how to set them up.

Does anyone have a working example of using matrix-free methods in this context?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 18, 2018, 12:14am UTC](https://discourse.julialang.org/t/matrix-free-linear-solvers-for-differentialequations-jl/10968/2 "2018-05-18T00:14:36Z")

</div>

It’s not ready yet. I have a plan for how to do it:

[https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/220](https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/220)

but it needs to get implemented. Until then, Sundials.jl exposes the whole API so you can define the ATimes function just fine if you pass a `cfunction` for it. So the direct interface should work, just the high level interface isn’t there yet. I wanna get it done this summer though…

---

<div class="post-metadata">

**Author:** ![rveltz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rveltz/32/2707_2.png) [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Post date:** [May 18, 2018, 5:24am UTC](https://discourse.julialang.org/t/matrix-free-linear-solvers-for-differentialequations-jl/10968/3 "2018-05-18T05:24:09Z")

</div>

you can use the python package petsc4py

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 18, 2018, 8:25am UTC](https://discourse.julialang.org/t/matrix-free-linear-solvers-for-differentialequations-jl/10968/4 "2018-05-18T08:25:42Z")

</div>

> [@rveltz](#):
>
> you can use the python package petsc4py

Or just PETSc.jl. But that doesn’t actually give us something new here. PETSc is actually using Sundials for its BDF implementations, so you might as well just call Sundials directly if that’s what you want since PETSc isn’t much of a higher level interface anyways.

---

<div class="post-metadata">

**Author:** ![tobydriscoll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tobydriscoll/32/1843_2.png) [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Post date:** [May 18, 2018, 6:31pm UTC](https://discourse.julialang.org/t/matrix-free-linear-solvers-for-differentialequations-jl/10968/5 "2018-05-18T18:31:58Z")

</div>

Didn’t think to search the repo issues. Thanks.
