Skip to content

Commit f56c738

Browse files
Merge pull request #1540 from SciML/static_chunksize
Make the chunksize determination static when static
2 parents 1ce7698 + 5769734 commit f56c738

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/alg_utils.jl

+13-1
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,22 @@ function DiffEqBase.prepare_alg(alg::Union{OrdinaryDiffEqAdaptiveImplicitAlgorit
171171
if typeof(alg) <: OrdinaryDiffEqImplicitExtrapolationAlgorithm
172172
return alg # remake fails, should get fixed
173173
else
174-
remake(alg,chunk_size=Val{ForwardDiff.pickchunksize(x)}())
174+
L = ArrayInterface.known_length(typeof(u0))
175+
if L === nothing # dynamic sized
176+
cs = ForwardDiff.pickchunksize(x)
177+
remake(alg,chunk_size=cs)
178+
else # statically sized
179+
cs = pick_static_chunksize(Val{L}())
180+
remake(alg,chunk_size=cs)
181+
end
175182
end
176183
end
177184

185+
@generated function pick_static_chunksize(::Val{chunksize}) where chunksize
186+
x = ForwardDiff.pickchunksize(chunksize)
187+
:(Val{$x}())
188+
end
189+
178190
function DiffEqBase.prepare_alg(alg::CompositeAlgorithm,u0,p,prob)
179191
algs = map(alg -> DiffEqBase.prepare_alg(alg, u0, p, prob), alg.algs)
180192
CompositeAlgorithm(algs, alg.choice_function)

0 commit comments

Comments
 (0)