@@ -37,7 +37,7 @@ function threadedsensitivities(react; odesolver=nothing, senssolver=nothing,
37
37
38
38
39
39
# Parallelize the SA calculations
40
- solutiondictionary = Dict ( )
40
+ solutions = Array {ODESolution} (undef, length (react . p) )
41
41
42
42
nthreads = Threads. nthreads ()
43
43
if nthreads > 1 # each thread needs its own Reactor
@@ -71,10 +71,10 @@ function threadedsensitivities(react; odesolver=nothing, senssolver=nothing,
71
71
odefcn = ODEFunction (dsdt!)
72
72
prob = ODEProblem (odefcn, zeros (length (r. y0)),r. tspan,0 )
73
73
s = solve (prob, senssolver; senskwargs... )
74
- solutiondictionary [i] = s
74
+ solutions [i] = s
75
75
end
76
76
77
- bigsol = generatesenssolution (sol,solutiondictionary ,reactsens. ode)
77
+ bigsol = generatesenssolution (sol,solutions ,reactsens. ode)
78
78
return bigsol
79
79
end
80
80
@@ -115,14 +115,15 @@ function threadedsensitivities(react, paramindices; odesolver=nothing, senssolve
115
115
116
116
117
117
# Parallelize the SA calculations
118
- solutiondictionary = Dict ( )
118
+ solutions = Array {ODESolution} (undef, length (paramindices) )
119
119
nthreads = Threads. nthreads ()
120
120
if nthreads > 1 # each thread needs its own Reactor
121
121
reacts = [deepcopy (react) for i in 1 : nthreads]
122
122
else
123
123
reacts = [react]
124
124
end
125
- @threads for i in paramindices
125
+ @threads for n in 1 : length (paramindices)
126
+ i = paramindices[n]
126
127
if nthreads > 1
127
128
id = Threads. threadid ()
128
129
r = reacts[id]
@@ -147,9 +148,9 @@ function threadedsensitivities(react, paramindices; odesolver=nothing, senssolve
147
148
odefcn = ODEFunction (dsdt!)
148
149
prob = ODEProblem (odefcn, zeros (length (r. y0)),r. tspan,0 )
149
150
s = solve (prob, senssolver; senskwargs... )
150
- solutiondictionary[i ] = s
151
+ solutions[n ] = s
151
152
end
152
-
153
+ solutiondictionary = [i => solutions[n] for (n,i) in enumerate (paramindices)]
153
154
return solutiondictionary
154
155
end
155
156
@@ -158,11 +159,10 @@ export threadedsensitivities
158
159
"""
159
160
Combine ODE solutions into a sensitivity solution
160
161
"""
161
- function generatesenssolution (sol, sensdict , sensprob)
162
+ function generatesenssolution (sol, senssolns , sensprob)
162
163
ts = sol. t
163
- ordkeys = sort ([x for x in keys (sensdict)])
164
+ u = [ vcat (sol . u[i],(senssolns[k](ts[i]) for k in 1 : length (senssolns)) . .. ) for i in 1 : length (sol . u)]
164
165
bigsol = build_solution (sensprob, sol. alg, ts, u;
165
166
interp= LinearInterpolation (ts, u), retcode= sol. retcode)
166
- u = [vcat (sol. u[i],(sensdict[k](ts[i]) for k in ordkeys). .. ) for i in 1 : length (sol. u)]
167
167
return bigsol
168
168
end
0 commit comments