Skip to content

Commit 139d6ed

Browse files
committed
added: testing @threads on geq
1 parent b67af59 commit 139d6ed

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/controller/transcription.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ plant model/constraints.
3131
struct SingleShooting <: ShootingMethod end
3232

3333
@doc raw"""
34-
MultipleShooting()
34+
MultipleShooting(threads=false)
3535
3636
Construct a direct multiple shooting [`TranscriptionMethod`](@ref).
3737
@@ -61,7 +61,11 @@ control horizon ``H_c``, unstable or highly nonlinear plant models/constraints.
6161
Sparse optimizers like `OSQP` or `Ipopt` and sparse Jacobian computations are recommended
6262
for this transcription method.
6363
"""
64-
struct MultipleShooting <: ShootingMethod end
64+
struct MultipleShooting{T} <: ShootingMethod
65+
function MultipleShooting(thread::Bool=false)
66+
return new{thread}()
67+
end
68+
end
6569

6670
@doc raw"""
6771
TrapezoidalCollocation(h::Int=0)
@@ -1212,15 +1216,14 @@ function predict!(
12121216
nu, ny, nd, nx̂, Hp, Hc = model.nu, model.ny, model.nd, mpc.estim.nx̂, mpc.Hp, mpc.Hc
12131217
X̂0 = @views Z̃[(nu*Hc+1):(nu*Hc+nx̂*Hp)] # Z̃ = [ΔU; X̂0; ϵ]
12141218
D̂0 = mpc.D̂0
1215-
local x̂0
12161219
for j=1:Hp
12171220
x̂0 = @views X̂0[(1 + nx̂*(j-1)):(nx̂*j)]
12181221
d̂0 = @views D̂0[(1 + nd*(j-1)):(nd*j)]
12191222
ŷ0 = @views Ŷ0[(1 + ny*(j-1)):(ny*j)]
12201223
ĥ!(ŷ0, mpc.estim, model, x̂0, d̂0)
12211224
end
12221225
Ŷ0 .+= mpc.F # F = Ŷs if mpc.estim is an InternalModel, else F = 0.
1223-
x̂0end .= x̂0
1226+
x̂0end .= @views X̂0[(1+nx̂*(Hp-1)):(nx̂*Hp)]
12241227
return Ŷ0, x̂0end
12251228
end
12261229

@@ -1329,15 +1332,14 @@ in which the augmented state ``\mathbf{x̂_0}`` are extracted from the decision
13291332
"""
13301333
function con_nonlinprogeq!(
13311334
geq, X̂0, Û0, K0,
1332-
mpc::PredictiveController, model::NonLinModel, ::MultipleShooting, U0, Z̃
1333-
)
1335+
mpc::PredictiveController, model::NonLinModel, ::MultipleShooting{T}, U0, Z̃
1336+
) where T
13341337
nu, nx̂, nd, nk = model.nu, mpc.estim.nx̂, model.nd, model.nk
13351338
Hp, Hc = mpc.Hp, mpc.Hc
13361339
nΔU, nX̂ = nu*Hc, nx̂*Hp
13371340
D̂0 = mpc.D̂0
1338-
X̂0_Z̃ = @views Z̃[(nΔU+1):(nΔU+nX̂)]
1341+
X̂0_Z̃ = @views Z̃[(nΔU+1):(nΔU+nX̂)]
13391342
Threads.@threads for j=1:Hp
1340-
#for j=1:Hp
13411343
if j < 2
13421344
x̂0 = @views mpc.estim.x̂0[1:nx̂]
13431345
d̂0 = @views mpc.d0[1:nd]

0 commit comments

Comments
 (0)