first time asking a question here. I previously used a simple MATLAB script to model 90 Hopf oscillators, coupled through a matrix, with randn noise, with a simple Euler step integration. I wanted to upgrade this, so I got into Julia, seems to have many exciting properties.
This is the system of equations I'm solving
I'm kinda lost. I started using differentialequations.jl (stochastic solver) , arrived to a solution, and found myself with a benchmark that tells me that solving 200 seconds occupies like 4 Gb!!! (2.5 Gb with alg_hints=[:stiff]) (I haven't fixed dt, previously I used dt=0.1)
function Shopf(du,u,p,t)
du[1:90,1]=(p[1:90,1]-u[1:90,1].^2.0-u[1:90,2].^2.0).*u[1:90,1]-p[1:90,2].*u[1:90,2] + 0.5*(-p[: , end].*u[:,1]+p[:,4:end-1] *u[:,1])
du[1:90,2]=(p[1:90,1]-u[1:90,1].^2.0-u[1:90,2].^2.0).*u[1:90,1]+p[1:90,2].*u[1:90,1] + 0.5*(-p[: , end].*u[:,2]+p[:,4:end-1] *u[:,2])
end
function σ_Shopf(du,u,p,t)
du[1:90,1]=0.04*ones(90,1)
du[1:90,2]=0.04*ones(90,1)
end
#initial condition
u0=-0.1*ones(90,2);
#initial time
t0=0.0;
#final time
tend=200.0;
#setting parameter matrix
p0=[0.1 , 2*pi*0.04]
push!(p0,-p0[2])
p=p0'.*ones(90,3);
SC=SC;
p=[p SC]
p=[p sum(SC,dims=2)]
#
#col 1 :alpha
#col 2-3 : [w0 -w0]
#col 3-93 : coupling matrix
#col 94: col-wise sum of coupling matrix
@benchmark solve(prob_sde_Shopf,nlsolver=Rosenbrock23(),alg_hints=[:stiff])
BenchmarkTools.Trial: memory estimate: 2.30 GiB
allocs estimate: 722769
minimum time: 859.224 ms (13.24% GC)
median time: 942.707 ms (13.10% GC)
mean time: 975.430 ms (12.99% GC)
maximum time: 1.223 s (13.00% GC)
samples: 6
evals/sample: 1
Any thoughts? I'm checking out several solutions, but none of them reduce the amount of memory to a reasonable amount. Thanks in advance.
SC
, except by writingSC=SC;
which doesn't help that much. It's also confusing that on the same line you useu[1:90,1]
andu[:,1]
as if they were the same size. Ifu
has 90 rows, then there is no reason to use those indices (and quite dangerous in fact), and if it doesn't then the code shouldn't work. – DNF