Hi all,
I am interested in been able to manually solve ODEs distributed as below. I am aware of ensembledistributed() however I want greater control over the outcome of each trajectory. My thinking is then to solve a serial process across a for loop which I distribute as I do not care about the order of the outputs.
My actual problem is loading a model using CellMLToolKit to load a model and formulate the problem that way. My aim is to solve across 2 nodes each with 64 cores. Are there any tips for doing things this way the cluster admins are fairly militant thus I thought better check first. MWE and Slurm script below.
CODE
using Distributed
addprocs(128)
@everywhere using OrdinaryDiffEq, QuasiMonteCarlo, JLD
@everywhere function f(du, u, p, t)
du[1] = p[1] * u[1] - p[2] * u[1] * u[2] #prey
du[2] = -p[3] * u[2] + p[4] * u[1] * u[2] #predator
end
@everywhere u0 = [1.0; 1.0]
@everywhere tspan = (0.0, 10.0)
@everywhere p = [1.5, 1.0, 3.0, 1.0]
@everywhere prob = ODEProblem(f, u0, tspan, p)
@everywhere t = collect(range(0, stop = 10, length = 200))
@everywhere function f_S(p)
prob_ = remake(prob, p = p)
sol = solve(prob_, Tsit5(), saveat = t)
[mean(sol[1,:]); mean(sol[2,:])]
end
# Generate parameter samples
@everywhere samples = 50000
@everywhere lb = [1.0, 1.0, 1.0, 1.0]
@everywhere ub = [5.0, 5.0, 5.0, 5.0]
@everywhere sampler = SobolSample()
@everywhere A, B = QuasiMonteCarlo.generate_design_matrices(samples, lb, ub, sampler)
# Analytical indices set up #
@everywhere N = 50000 # samples
@everywhere D = 4 # parameters
@everywhere M = 2 # outputs
# Initialize results matrices
@everywhere y_AB = zeros(M, N, D)
# A_B Matrix evaluation #
@distributed for i in 1:N
for j in 1:D
AB = copy(A[:,i])
AB[j] = B[j,i]
y_AB[:,i,j] = f_S(AB)
end
end
save("y_AB.jld","data",y_AB)
Slurm Script
#!/bin/bash
#SBATCH --job-name=Dis
#SBATCH --time=96:00:00
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=64
#SBATCH --output="Log.txt"
#SBATCH --error="err.txt"
#/users/ac1hsax/julia-1.10.5/bin/julia --threads 128 CourtDis.jl