Hello All,
This is a follow up to my question posted here.
Iβve installed Julia in windows and I am running the following code (posted in the above-mentioned link) via the Julia plugin instaled in Pycharm.
using DifferentialEquations, BenchmarkTools
mat1=[
1 -2 1 0 0 0 0 0 0 0;
0 1 -2 1 0 0 0 0 0 0;
0 0 1 -2 1 0 0 0 0 0;
0 0 0 1 -2 1 0 0 0 0;
0 0 0 0 1 -2 1 0 0 0;
0 0 0 0 0 1 -2 1 0 0;
0 0 0 0 0 0 1 -2 1 0;
0 0 0 0 0 0 0 1 -2 1;
];
mat2 = [
1 -1 0 0 0 0 0 0 0 0;
0 1 -1 0 0 0 0 0 0 0;
0 0 1 -1 0 0 0 0 0 0;
0 0 0 1 -1 0 0 0 0 0;
0 0 0 0 1 -1 0 0 0 0;
0 0 0 0 0 1 -1 0 0 0;
0 0 0 0 0 0 1 -1 0 0;
0 0 0 0 0 0 0 1 -1 0;
];
x0 = [1.0,0,0,0,0,0,0,0,0,0]
saveat = 0:0.01:5
function fun(dx,x,p,t)
dx[1,:] .= 0
dx[2:9,:] .= mat1*x + mat2*x
dx[10,:] .= 2*(x[end-1] - x[end])
end
prob = ODEProblem(fun,x0,(0.0,5.0))
sys = modelingtoolkitize(prob)
fastprob = ODEProblem(sys,x0,(0.0,5.0),jac=true)
# Explicit RK Methods
@btime sol = solve(fastprob,Tsit5()) # 16.700 ΞΌs (245 allocations: 40.28 KiB)
@btime sol = solve(fastprob,BS3()) # 19.800 ΞΌs (231 allocations: 33.70 KiB)
@btime sol = solve(fastprob,Vern7()) # 18.400 ΞΌs (266 allocations: 49.62 KiB)
# Stabilized-Explicit RK Methods
@btime sol = solve(fastprob,ROCK2()) # 173.300 ΞΌs (831 allocations: 159.59 KiB)
@btime sol = solve(fastprob,ROCK4()) # 237.100 ΞΌs (1958 allocations: 191.64 KiB)
# Implicit and Semi-Implicit Methods
@btime sol = solve(fastprob,Rosenbrock23()) # 83.200 ΞΌs (541 allocations: 53.50 KiB)
@btime sol = solve(fastprob,TRBDF2()) # 72.400 ΞΌs (297 allocations: 31.72 KiB)
@btime sol = solve(fastprob,KenCarp47()) # 110.500 ΞΌs (444 allocations: 33.02 KiB)
sparseprob = ODEProblem(sys,x0,(0.0,5.0),jac=true,sparse=true)
@btime sol = solve(sparseprob,Rosenbrock23()) # 670.000 ΞΌs (3505 allocations: 1.22 MiB)
@btime sol = solve(sparseprob,TRBDF2()) # 254.000 ΞΌs (1332 allocations: 414.91 KiB)
@btime sol = solve(sparseprob,KenCarp47()) # 346.400 ΞΌs (1757 allocations: 525.05 KiB)
using Setfield, LinearAlgebra
f = fastprob.f
newf = @set f.jac_prototype = Tridiagonal(sparseprob.f.jac_prototype)
newf = @set newf.sparsity = Tridiagonal(sparseprob.f.sparsity)
tridiagprob = ODEProblem(newf,x0,(0.0,5.0))
@btime sol = solve(tridiagprob,Rosenbrock23()) # 188.000 ΞΌs (556 allocations: 66.19 KiB)
@btime sol = solve(tridiagprob,TRBDF2()) # 87.800 ΞΌs (338 allocations: 40.31 KiB)
@btime sol = solve(tridiagprob,KenCarp47()) # 133.400 ΞΌs (482 allocations: 42.16 KiB)
Iβm not sure why but I observe time in ms and not in microseconds as posted by @ChrisRackauckas on SE.
2.847 ms (34957 allocations: 2.63 MiB)
2.985 ms (31647 allocations: 1.73 MiB)
3.721 ms (46812 allocations: 5.47 MiB)
22.349 ms (268252 allocations: 10.67 MiB)
5.789 ms (80043 allocations: 3.01 MiB)
78.085 ms (605234 allocations: 20.99 MiB)
25.611 ms (217583 allocations: 7.47 MiB)
33.834 ms (288531 allocations: 10.52 MiB)
74.903 ms (597849 allocations: 20.82 MiB)
25.356 ms (210161 allocations: 7.29 MiB)
34.504 ms (281243 allocations: 10.33 MiB)
11.809 ms (156756 allocations: 4.92 MiB)
7.047 ms (72883 allocations: 2.52 MiB)
9.795 ms (103225 allocations: 4.15 MiB)
Could someone help me in understanding why it takes ms and not microseconds when I run the code ?
Thanks so much