Open redsnic opened 7 months ago
Updated example for MTK v9:
using Plots, DifferentialEquations, CUDA, StaticArrays, DiffEqGPU, ModelingToolkit
# works below 33, fails above
n_x = 33
@variables t
D = Differential(t)
@variables X(t)[1:n_x]
eqs = []
for i in 1:n_x
push!(eqs, D(X[i]) ~ Num(1.0))
end
p = @SVector [1.0 for i in 1:n_x]
u0 = @SVector [1.0 for i in 1:n_x]
tspan = (0.0, 10.0)
@mtkbuild sys = ODESystem(eqs, t)
prob = ODEProblem(sys, u0, tspan) # the problem must be out-of-place
# solve on CPU
sol = solve(prob, Tsit5(), saveat=0.1)
plot(sol, idxs=1:n_x)
# prepare the problem for the GPU
problem_func = (problem, i, repeat) -> remake(problem) # randomize the initial condition
multi_problem = EnsembleProblem(prob; prob_func = problem_func, safetycopy = false)
# solve on GPU
solutions = solve(multi_problem, GPUTsit5(), EnsembleGPUKernel(CUDA.CUDABackend()), trajectories=10, adaptive = true, reltol=1e-6, abstol=1e-6, saveat=0.1)
# plot the results
for s in solutions
plot!(s, idxs=1:n_x, linestyle=:dash, legend=false)
end
plot!()
The issue is the StaticArrays splat limit I think? @vchuravy is there a way around this?
Hello, I have a question regarding an error that I am facing when solving systems of ODEs with more than 32 equations:
you can take a look at this other github issue especially to the last example, that I am posting here again for completeness:
This code fails with the following error:
Do you have an idea on why this is happening? I am using a Titan RTX on my machine. Let me know if you need additional information.
Thank you in advance.