Skip to content

Commit

Permalink
🔧 Improve multithreaded propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr committed Jun 19, 2024
1 parent eba2dce commit c9e01cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/api/Propagators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,21 @@ function propagate!(
# Make sure the number of tasks is not higher than the number of propagation points.
ntasks = min(ntasks, len_vt)

@maybe_threads ntasks for c in 1:ntasks
# We already propagated for the first instant, and we must ensure we propagate the
# last instant at the end of the function.
cinds = @views inds[(1 + begin):(end - 1)]
i₀, i₁ = get_partition(c, cinds, ntasks)

# The propagation usually modifies the structure. Hence we need to copy it for each
# task.
corbp = c == 1 ? orbp : copy(orbp)

length(cinds) != 0 && @inbounds for i in i₀:i₁
vr[i - Δi], vv[i - Δi] = Propagators.propagate!(corbp, vt[i])
# If we have only two instants in the time vector, we will not spawn any threads,
# because the first and the last instants are propagated separately.
if len_vt > 2
@maybe_threads ntasks for c in 1:ntasks
# We already propagated for the first instant, and we must ensure we propagate
# the last instant at the end of the function.
i₀, i₁ = @views get_partition(c, inds[(1 + begin):(end - 1)], ntasks)

# The propagation usually modifies the structure. Hence we need to copy it for each
# task.
corbp = c == 1 ? orbp : copy(orbp)

@inbounds for i in i₀:i₁
vr[i - Δi], vv[i - Δi] = Propagators.propagate!(corbp, vt[i])
end
end
end

Expand Down
12 changes: 12 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,70 +45,82 @@ PrecompileTools.@setup_workload begin
orbp = Propagators.init(Val(:J2), orb)
Propagators.propagate!(orbp, 0.0)
Propagators.propagate!(orbp, [0.0, 1.0])
Propagators.propagate!(orbp, [0.0, 1.0, 2.0])
Propagators.fit_mean_elements!(orbp, vjd, vr_i, vv_i)
Propagators.fit_mean_elements(Val(:J2), vjd, vr_i, vv_i)

orbp = Propagators.init(Val(:J2), orb; j2c = j2c_egm2008_f32)
Propagators.propagate!(orbp, 0.0f0)
Propagators.propagate!(orbp, [0.0f0, 1.0f0])
Propagators.propagate!(orbp, [0.0f0, 1.0f0, 2.0f0])

# == J2 Osculating Orbit Propagator ============================================

orbp = Propagators.init(Val(:J2osc), orb)
Propagators.propagate!(orbp, 0.0)
Propagators.propagate!(orbp, [0.0, 1.0])
Propagators.propagate!(orbp, [0.0, 1.0, 2.0])
Propagators.fit_mean_elements!(orbp, vjd, vr_i, vv_i)
Propagators.fit_mean_elements(Val(:J2osc), vjd, vr_i, vv_i)

orbp = Propagators.init(Val(:J2osc), orb; j2c = j2c_egm2008_f32)
Propagators.propagate!(orbp, 0.0f0)
Propagators.propagate!(orbp, [0.0f0, 1.0f0])
Propagators.propagate!(orbp, [0.0f0, 1.0f0, 2.0f0])

# == J4 Orbit Propagator =======================================================

orbp = Propagators.init(Val(:J4), orb)
Propagators.propagate!(orbp, 0.0)
Propagators.propagate!(orbp, [0.0, 1.0])
Propagators.propagate!(orbp, [0.0, 1.0, 2.0])
Propagators.fit_mean_elements!(orbp, vjd, vr_i, vv_i)
Propagators.fit_mean_elements(Val(:J4), vjd, vr_i, vv_i)

orbp = Propagators.init(Val(:J4), orb; j4c = j4c_egm2008_f32)
Propagators.propagate!(orbp, 0.0f0)
Propagators.propagate!(orbp, [0.0f0, 1.0f0])
Propagators.propagate!(orbp, [0.0f0, 1.0f0, 2.0f0])

# == J4 Osculating Orbit Propagator ============================================

orbp = Propagators.init(Val(:J4osc), orb)
Propagators.propagate!(orbp, 0.0)
Propagators.propagate!(orbp, [0.0, 1.0])
Propagators.propagate!(orbp, [0.0, 1.0, 2.0])
Propagators.fit_mean_elements!(orbp, vjd, vr_i, vv_i)
Propagators.fit_mean_elements(Val(:J4osc), vjd, vr_i, vv_i)

orbp = Propagators.init(Val(:J4osc), orb; j4c = j4c_egm2008_f32)
Propagators.propagate!(orbp, 0.0f0)
Propagators.propagate!(orbp, [0.0f0, 1.0f0])
Propagators.propagate!(orbp, [0.0f0, 1.0f0, 2.0f0])

# == SGP4 Orbit Propagator =====================================================

orbp = Propagators.init(Val(:SGP4), tle)
Propagators.propagate!(orbp, 0.0)
Propagators.propagate!(orbp, [0.0, 1.0])
Propagators.propagate!(orbp, [0.0, 1.0, 2.0])
Propagators.fit_mean_elements!(orbp, vjd, vr_i, vv_i)
Propagators.fit_mean_elements(Val(:SGP4), vjd, vr_i, vv_i)

orbp = Propagators.init(Val(:SGP4), tle; sgp4c = sgp4c_wgs84_f32)
Propagators.propagate!(orbp, 0.0f0)
Propagators.propagate!(orbp, [0.0f0, 1.0f0])
Propagators.propagate!(orbp, [0.0f0, 1.0f0, 2.0f0])

# == Two Body Orbit Propagator =================================================

orbp = Propagators.init(Val(:TwoBody), orb)
Propagators.propagate!(orbp, 0.0)
Propagators.propagate!(orbp, [0.0, 1.0])
Propagators.propagate!(orbp, [0.0, 1.0, 2.0])

orbp = Propagators.init(Val(:TwoBody), orb; m0 = tbc_m0_f32)
Propagators.propagate!(orbp, 0.0f0)
Propagators.propagate!(orbp, [0.0f0, 1.0f0])
Propagators.propagate!(orbp, [0.0f0, 1.0f0, 2.0f0])
end
end
end

0 comments on commit c9e01cb

Please sign in to comment.