SciML / SciML/RecursiveArrayTools.jl

Excessive allocations with VectorOfArray in broadcast

Open
#199 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
233
Forks
76
Avg merge
2h 17m
Merged PRs (30d)
9

Description

I am using a VectorOfArray as state vector in DifferentialEquations. This leads to too many allocations.

using DifferentialEquations
using RecursiveArrayTools

# Set up the state vector
U = VectorOfArray([zeros(100,100,100), zeros(100,100,100)]);
rhs!(U̇, U, p, t) = U̇ .= U

# Compile all code
prob = ODEProblem(rhs!, U, (0.0, 1.0));
sol = solve(prob, RK4(); adaptive=false, dt=1.0);

# Benchmark
prob = ODEProblem(rhs!, U, (0.0, 1.0));
@time sol = solve(prob, RK4(); adaptive=false, dt=1.0);

This outputs

  1.639028 seconds (42.00 M allocations: 991.828 MiB, 18.67% gc time)

Note the very large number of allocations. It seems as if some operation was performing one small allocation per array element.

(I notice that this problem disappears if I switch to the midpoint rule.)

I tried with both Julia 1.7 and the current release branch of Julia 1.8.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reported VectorOfArray reproducer with DifferentialEquations, ODEProblem, RK4, and the rhs! benchmark, then compare it with the midpoint rule. Trace the allocations during the solve and identify the operation responsible for the per-element allocations; done means the RK4 case no longer shows excessive allocations while retaining the reported solve behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.