Parallelizing GSA - A size issue

Hi,

I am looking to try and speed up my code and trying to following the example in the documentation here

On running the below

x = [prob.u0;prob.p]
function circ(x)
    prob_func(prob,i,repeat) = remake(prob;u0 = x[1:3,i], p=x[4:end,i])
    ensemble_prob = EnsembleProblem(prob,prob_func = prob_func)
    newsol = solve(ensemble_prob, Rodas5(), EnsembleThreads(), reltol=1e-6, abstol=1e-12; saveat = savetime, trajectories = size(x,10))
    ## Sol[i] is the solution for the ith set of parameters 
    out = zeros(10,size(x,10))
    for i in 1:size(x,10)
        out[1,i]= (maximum(newsol[i][LV.V])-minimum(newsol[i][LV.V]))
        out[2,i]= mean(newsol[i][LV.V])
        out[3,i]= (maximum(newsol[i][LV.p])-minimum(newsol[i][LV.p]))
        out[4,i]= mean(newsol[i][LV.p])
        out[5,i]= (maximum(newsol[i][Csa.in.p])-minimum(newsol[i][Csa.in.p]))
        out[6,i]= mean(newsol[i][Csa.in.p])
        out[7,i]= maximum(newsol[i][Csa.q])
        out[8,i]= maximum(newsol[i][Csv.q])
        out[9,i]= maximum(newsol[i][LV.p])/mean(newsol[i][LV.p])
        out[10,i]= maximum(newsol[i][Csa.in.p])/mean(newsol[i][Csa.in.p])
    end
    out 
end


lb = [4.9, -9.1, -9.1, 1.05, 0.021, 0.924, 15.33, 0.8, 0.180285, 0.34233, 1.1704, 0.0231, 0.0042, 0.777, 0.791, 7.7]
ub = [9.1, -4.9, -4.9, 1.95, 0.039, 1.716, 28.47, 0.9, 0.334815, 0.56134, 2.1736, 0.0429, 0.0078, 1.443, 1.469, 14.3]

N=2500
bounds = tuple.(lb,ub)
sampler = SobolSample()
A,B = QuasiMonteCarlo.generate_design_matrices(N, lb, ub, sampler)
@time sobol_result = gsa(circ,Sobol(),A,B, batch = true)

It throws the bounds error of

ERROR: BoundsError: attempt to access 10×1 Matrix{Float64} at index [1:10, 1:5000]
Stacktrace:
 [1] throw_boundserror(A::Matrix{Float64}, I::Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}})
   @ Base ./abstractarray.jl:691
 [2] checkbounds
   @ ./abstractarray.jl:656 [inlined]
 [3] _getindex
   @ ./multidimensional.jl:838 [inlined]
 [4] getindex
   @ ./abstractarray.jl:1218 [inlined]
 [5] gsa_sobol_all_y_analysis(method::Sobol, all_y::Matrix{Float64}, d::Int64, n::Int64, Ei_estimator::Symbol, y_size::Nothing, #unused#::Val{true})
   @ GlobalSensitivity ~/.julia/packages/GlobalSensitivity/Xw0Ui/src/sobol_sensitivity.jl:116
 [6] gsa(f::typeof(circ), method::Sobol, A::Matrix{Float64}, B::Matrix{Float64}; batch::Bool, Ei_estimator::Symbol, distributed::Val{false}, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ GlobalSensitivity ~/.julia/packages/GlobalSensitivity/Xw0Ui/src/sobol_sensitivity.jl:59
 [7] top-level scope
   @ ./timing.jl:220 [inlined]

Running the serial version of this runs as expected. I suspect the error to be around where I define out however I am just sure i understand why I am getting the error.

Cheers :slight_smile:

I am confused what you intend this to do, I think this might be the issue. Arrays · The Julia Language, the second argument to size is the dimension of which you want the length, so I think iiuc you want to do size(x,2) inlace of size(x, 10)