astro-group-bristol / Gradus.jl

Extensible spacetime agnostic general relativistic ray-tracing (GRRT).
https://astro-group-bristol.github.io/Gradus.jl/dev/
GNU General Public License v3.0
18 stars 2 forks source link

Feat: better put out the bins for garbage collection #85

Closed fjebaker closed 1 year ago

fjebaker commented 1 year ago
using Gradus

m = KerrMetric(M = 1.0, a = 1.0)
u = @SVector [0.0, 1e6, deg2rad(60), 0.0]
d = GeometricThinDisc(Gradus.isco(m), 500.0, deg2rad(90.0))

model = LampPostModel()
plane = PolarPlane(GeometricGrid(); Nr = 800, Nθ = 800)

begin
    GC.gc()
    tf = @time lagtransfer(model, m, u, plane, d, callback = domain_upper_hemisphere())
end

# old
#  44.711429 seconds (18.92 M allocations: 6.857 GiB, 17.81% gc time)
# new
#  34.577995 seconds (7.88 M allocations: 1.671 GiB)

This might start getting quite confusing, but there is now a new ensemble method in Gradus which reuses integrators provided only the endpoints of the geodesic are needed -- EnsembleEndpointThreads. This saves a considerable number of allocations, as can be seen above.

The same principle could also be used anywhere where the full solutions aren't required, such as in the precision integrators -- instead of setting up a full solution again, we just init and reinit as needed.

I will add that to the next PR to improve those methods.

Is a step towards #82 👍

fjebaker commented 1 year ago
using Gradus

m = KerrMetric(M = 1.0, a = 0.6)
u = @SVector [0.0, 1000.0, deg2rad(60), 0.0]
d = GeometricThinDisc(0.0, 100.0, π/2)

begin
    GC.gc()
    println("Start...")
    α, β = @time impact_parameters_for_radius(m, u, d, 5.0, N=1000)
    ""
end

# old: N = 1000
#  1.296828 seconds (1.05 M allocations: 245.828 MiB)
# old: N = 10000
#  12.974839 seconds (10.60 M allocations: 2.422 GiB, 1.63% gc time)
# new: N = 1000
#  1.279600 seconds (334.35 k allocations: 69.610 MiB)
# new: N = 10000
#  12.846616 seconds (3.37 M allocations: 701.538 MiB)