Skip to content

Commit b83aca4

Browse files
committed
Print timings
1 parent a1d731e commit b83aca4

File tree

3 files changed

+76
-62
lines changed

3 files changed

+76
-62
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1111
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
1212
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1313
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
14+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
1415
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1516
UnitfulAtomic = "a7773ee8-282e-5fa2-be4e-bd808c38a91a"
1617

src/StrongFieldApproximation.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using LinearAlgebra
99
using StaticArrays
1010

1111
using ProgressMeter
12+
using TimerOutputs
1213

1314
include("threading.jl")
1415
include("telescope_iterators.jl")

src/dyson_expansions.jl

Lines changed: 74 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -424,77 +424,82 @@ function recombination(system::System, diagram::Diagram, 𝐩, 𝐀, i)
424424
end
425425
end
426426

427-
function integrate_diagram(::Type{Amp}, system::System, diagram::Diagram, iref, 𝐤=nothing; memory=typemax(Int), imin=1) where Amp
428-
ions, unique_momenta, momenta, indeterminate_momenta, order = analyze_diagram(system, diagram)
427+
function integrate_diagram(::Type{Amp}, system::System, diagram::Diagram, iref, 𝐤=nothing; memory=typemax(Int), imin=1,
428+
to=TimerOutput(), verbosity=1) where Amp
429+
ions, unique_momenta, momenta, indeterminate_momenta, order = @timeit to "Analyze diagram" analyze_diagram(system, diagram)
429430

430-
weight = (-im*system.dt)^order
431+
@timeit to "Allocations" begin
432+
weight = (-im*system.dt)^order
431433

432-
# println()
433-
# @info "Integrating diagram up to" iref system diagram ions unique_momenta momenta indeterminate_momenta order weight 𝐤
434+
verbosity > 1 && @info "Integrating diagram up to" iref system diagram ions unique_momenta momenta indeterminate_momenta order weight 𝐤
434435

435-
# @show
436-
Eᵢₒₙₛ = [system.ionization_channels[ion].E for ion in ions]
437-
𝐩s = complex(zeros(momentum_type(system, 𝐤), length(unique_momenta)))
438-
prefactors = ones(complex(eltype(system.t)), length(unique_momenta))
439-
if !isnothing(𝐤)
440-
𝐩s[1] = 𝐤
436+
Eᵢₒₙₛ = [system.ionization_channels[ion].E for ion in ions]
437+
𝐩s = complex(zeros(momentum_type(system, 𝐤), length(unique_momenta)))
438+
prefactors = ones(complex(eltype(system.t)), length(unique_momenta))
439+
if !isnothing(𝐤)
440+
𝐩s[1] = 𝐤
441+
end
442+
443+
𝐀 = system.𝐀
444+
amplitude = complex(zero(Amp))
445+
ctT = complex(eltype(system.t))
446+
447+
is = vcat(iref, zeros(Int, order))
441448
end
442-
# @show 𝐩s
443449

444-
𝐀 = system.𝐀
445-
amplitude = complex(zero(Amp))
446-
ctT = complex(eltype(system.t))
447-
448-
is = vcat(iref, zeros(Int, order))
449-
450-
for i in TelescopeIterator(max(1,imin):iref-1, order, memory)
451-
is[2:end] .= i
452-
# is = vcat(iref, i)
453-
# is = (iref,i...)
454-
# for i in 1:iref-1, j in 1:i-1
455-
# is = (iref,i,j)
456-
# println(is)
457-
458-
evaluate_momenta!(𝐩s, prefactors, system, unique_momenta, indeterminate_momenta, is)
459-
# @show 𝐩s prefactors
460-
461-
Sᵢₒₙ = zero(ctT)
462-
Sₑₗ = zero(ctT)
463-
for j = 1:order
464-
a,b = is[j], is[j+1]
465-
τ = system.t[a] - system.t[b]
466-
Sᵢₒₙ += Eᵢₒₙₛ[j]*τ
467-
Sₑₗ += volkov_phase(𝐩s[j], system.volkov, a, b)
468-
end
469-
S = Sᵢₒₙ + Sₑₗ
470-
aₚᵣₒₚ = prod(prefactors)*exp(-im*S)
450+
@timeit to "Time loop" begin
451+
for i in TelescopeIterator(max(1,imin):iref-1, order, memory)
452+
is[2:end] .= i
453+
# is = vcat(iref, i)
454+
# is = (iref,i...)
455+
# for i in 1:iref-1, j in 1:i-1
456+
# is = (iref,i,j)
457+
# println(is)
458+
459+
@timeit to "Evaluate momenta" evaluate_momenta!(𝐩s, prefactors, system, unique_momenta, indeterminate_momenta, is)
460+
verbosity > 10 && @show 𝐩s prefactors
461+
462+
@timeit to "Evaluate propagators" begin
463+
Sᵢₒₙ = zero(ctT)
464+
Sₑₗ = zero(ctT)
465+
for j = 1:order
466+
a,b = is[j], is[j+1]
467+
τ = system.t[a] - system.t[b]
468+
Sᵢₒₙ += Eᵢₒₙₛ[j]*τ
469+
Sₑₗ += volkov_phase(𝐩s[j], system.volkov, a, b)
470+
end
471+
S = Sᵢₒₙ + Sₑₗ
472+
aₚᵣₒₚ = prod(prefactors)*exp(-im*S)
473+
end
471474

472-
# @show is prefactors
475+
verbosity > 10 && @show is prefactors
473476

474-
∂a = (ionization(system, diagram, 𝐩s[end], 𝐀, is[end]) *
475-
aₚᵣₒₚ *
476-
recombination(system, diagram, 𝐩s[1], 𝐀, iref))
477+
∂a = @timeit to "Prefactor" (ionization(system, diagram, 𝐩s[end], 𝐀, is[end]) *
478+
aₚᵣₒₚ *
479+
recombination(system, diagram, 𝐩s[1], 𝐀, iref))
477480

478-
# Loop over "interior" interactions
479-
for j = (order>1 && first(diagram)[2]==0 ? 3 : 2):order
480-
ion,which = diagram.path[j-1]
481-
α = ions[j-1]
482-
β = ions[j]
483-
# @show j, ion, which α,β
484-
interaction = system.couplings[which][α,β]
481+
@timeit to "Interior interactions" begin
482+
# Loop over "interior" interactions
483+
for j = (order>1 && first(diagram)[2]==0 ? 3 : 2):order
484+
ion,which = diagram.path[j-1]
485+
α = ions[j-1]
486+
β = ions[j]
487+
verbosity > 20 && @show j, ion, which α,β
488+
interaction = system.couplings[which][α,β]
485489

486-
𝐤ᵢ = 𝐩s[momenta[j-1]]
487-
𝐩ᵢ = 𝐩s[momenta[j]]
488-
𝐀ᵢ = 𝐀[is[j]]
490+
𝐤ᵢ = 𝐩s[momenta[j-1]]
491+
𝐩ᵢ = 𝐩s[momenta[j]]
492+
𝐀ᵢ = 𝐀[is[j]]
489493

490-
∂a *= interaction(kinematic_momentum(𝐤ᵢ, 𝐀ᵢ), kinematic_momentum(𝐩ᵢ, 𝐀ᵢ), is[j+1])
491-
end
494+
∂a *= @timeit to "Interaction" interaction(kinematic_momentum(𝐤ᵢ, 𝐀ᵢ), kinematic_momentum(𝐩ᵢ, 𝐀ᵢ), is[j+1])
495+
end
496+
end
492497

493-
# ∂a = prod(prefactors)
494-
amplitude += ∂a
498+
amplitude += ∂a
499+
end
495500
end
496501

497-
weight*amplitude
502+
@timeit to "Weighting" weight*amplitude
498503
end
499504

500505
# * High-level interface
@@ -507,11 +512,18 @@ function photoelectron_spectrum(k::AbstractArray{T},
507512

508513
cT = complex(eltype(T))
509514
c = similar(k, cT)
515+
to = TimerOutput()
510516
p = Progress(length(k))
511-
threaded_range_loop(eachindex(k)) do i
512-
c[i] = integrate_diagram(cT, system, diagram, iref, k[i]; kwargs...)
513-
ProgressMeter.next!(p)
517+
@timeit to "k loop" begin
518+
threaded_range_loop(eachindex(k)) do i
519+
tok = TimerOutput()
520+
c[i] = integrate_diagram(cT, system, diagram, iref, k[i]; to=tok, verbosity=verbosity-1, kwargs...)
521+
ProgressMeter.next!(p)
522+
merge!(to, tok, tree_point=["k loop"])
523+
end
514524
end
525+
TimerOutputs.complement!(to)
526+
verbosity > 0 && print_timer(to)
515527
c
516528
end
517529

@@ -537,7 +549,7 @@ function induced_dipole(system::System, diagram::Diagram; verbosity = 1, kwargs.
537549
memory = get(kwargs, :memory, typemax(Int))
538550

539551
@showprogress for (i,t) in enumerate(t)
540-
𝐝̃ = integrate_diagram(DT, system, diagram, i; imin=i-memory, kwargs...)
552+
𝐝̃ = integrate_diagram(DT, system, diagram, i; imin=i-memory, verbosity=verbosity-1, kwargs...)
541553
𝐝[i] = 2real(𝐝̃)
542554
end
543555

0 commit comments

Comments
 (0)