Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove performance-/precompilation-time harmful @eval #3556

Merged
merged 34 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6bac83d
bugfix
simone-silvestri Mar 1, 2024
a077af4
Merge branch 'main' of github.com:CliMA/Oceananigans.jl
simone-silvestri Mar 5, 2024
d0215e9
Merge branch 'main' of github.com:CliMA/Oceananigans.jl
simone-silvestri Mar 6, 2024
b9fbdbc
Merge branch 'main' of github.com:CliMA/Oceananigans.jl
simone-silvestri Mar 8, 2024
fea4bed
Merge branch 'main' of github.com:CliMA/Oceananigans.jl
simone-silvestri Mar 19, 2024
c4bfcd8
Merge branch 'main' of github.com:CliMA/Oceananigans.jl
simone-silvestri Mar 27, 2024
02bfe37
Merge branch 'main' of github.com:CliMA/Oceananigans.jl
simone-silvestri Apr 5, 2024
e1be27f
Merge branch 'main' of github.com:CliMA/Oceananigans.jl
simone-silvestri Apr 12, 2024
a03e980
remove evals
simone-silvestri Apr 18, 2024
d1d013a
remove other eval
simone-silvestri Apr 18, 2024
34903d9
bugfix
simone-silvestri Apr 19, 2024
107faca
Update src/Grids/latitude_longitude_grid.jl
simone-silvestri Apr 19, 2024
9b7cf49
remove yet another eval
simone-silvestri Apr 19, 2024
69ffc71
Merge branch 'ss/remove-harmful-eval' of github.com:CliMA/Oceananigan…
simone-silvestri Apr 19, 2024
9984ddf
bugfix
simone-silvestri Apr 19, 2024
15e93ef
Update src/Grids/latitude_longitude_grid.jl
simone-silvestri Apr 20, 2024
4616d17
Update src/Grids/latitude_longitude_grid.jl
simone-silvestri May 14, 2024
62bdad4
simplify code
simone-silvestri May 14, 2024
4226ef3
name change to reconstruction_coefficients function
simone-silvestri May 14, 2024
a57058a
Merge remote-tracking branch 'origin/main' into ss/remove-harmful-eval
simone-silvestri May 14, 2024
89b2728
Merge branch 'main' into ss/remove-harmful-eval
simone-silvestri May 15, 2024
974d786
bugfix
simone-silvestri May 19, 2024
42581e4
Merge branch 'ss/remove-harmful-eval' of https://github.com/CliMA/Oce…
simone-silvestri May 19, 2024
f7722fd
last bugfix
simone-silvestri May 20, 2024
781991d
Merge branch 'main' into ss/remove-harmful-eval
simone-silvestri Jun 19, 2024
db17a93
Replace a couple of evals with getglobal
vchuravy Jun 21, 2024
01d4c22
Mark a few places where eval needs to be removed
vchuravy Jun 21, 2024
87f73b4
Replace eval within interpolations utils with getglobal
vchuravy Jun 21, 2024
4f977f2
removed last evals
simone-silvestri Jun 21, 2024
b8f2471
Merge branch 'ss/remove-harmful-eval' of github.com:CliMA/Oceananigan…
simone-silvestri Jun 21, 2024
62f620c
Merge branch 'main' into ss/remove-harmful-eval
simone-silvestri Jun 21, 2024
ba63e17
correct typo
simone-silvestri Jun 21, 2024
288b9eb
Merge branch 'main' into ss/remove-harmful-eval
simone-silvestri Jun 23, 2024
67dab94
correct typos
simone-silvestri Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/Advection/reconstruction_coefficients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,24 +210,24 @@ end

method = scheme == :Centered ? 1 : scheme == :Upwind ? 2 : 3

rect_metrics = (:xᶠᵃᵃ, :xᶜᵃᵃ, :yᵃᶠᵃ, :yᵃᶜᵃ, :zᵃᵃᶠ, :zᵃᵃᶜ)

if grid isa Nothing
for metric in rect_metrics
@eval $(Symbol(:coeff_ , metric)) = nothing
@eval $(Symbol(:smooth_, metric)) = nothing
end
coeff_xᶠᵃᵃ = nothing
coeff_xᶜᵃᵃ = nothing
coeff_yᵃᶠᵃ = nothing
coeff_yᵃᶜᵃ = nothing
coeff_zᵃᵃᶠ = nothing
coeff_zᵃᵃᶜ = nothing
else
metrics = coordinates(grid)
dirsize = (:Nx, :Nx, :Ny, :Ny, :Nz, :Nz)

arch = architecture(grid)
Hx, Hy, Hz = halo_size(grid)
new_grid = with_halo((Hx+1, Hy+1, Hz+1), grid)

for (dir, metric, rect_metric) in zip(dirsize, metrics, rect_metrics)
@eval $(Symbol(:coeff_ , rect_metric)) = calc_reconstruction_coefficients($FT, $new_grid.$metric, $arch, $new_grid.$dir, Val($method); order = $order)
end
coeff_xᶠᵃᵃ = calc_reconstruction_coefficients(FT, getproperty(metrics[1], new_grid), arch, new_grid.Nx, Val(method); order)
simone-silvestri marked this conversation as resolved.
Show resolved Hide resolved
coeff_xᶜᵃᵃ = calc_reconstruction_coefficients(FT, getproperty(metrics[2], new_grid), arch, new_grid.Nx, Val(method); order)
coeff_yᵃᶠᵃ = calc_reconstruction_coefficients(FT, getproperty(metrics[3], new_grid), arch, new_grid.Ny, Val(method); order)
coeff_yᵃᶜᵃ = calc_reconstruction_coefficients(FT, getproperty(metrics[4], new_grid), arch, new_grid.Ny, Val(method); order)
coeff_zᵃᵃᶠ = calc_reconstruction_coefficients(FT, getproperty(metrics[5], new_grid), arch, new_grid.Nz, Val(method); order)
coeff_zᵃᵃᶜ = calc_reconstruction_coefficients(FT, getproperty(metrics[6], new_grid), arch, new_grid.Nz, Val(method); order)
end

return (coeff_xᶠᵃᵃ, coeff_xᶜᵃᵃ, coeff_yᵃᶠᵃ, coeff_yᵃᶜᵃ, coeff_zᵃᵃᶠ, coeff_zᵃᵃᶜ)
Expand Down
25 changes: 9 additions & 16 deletions src/Grids/latitude_longitude_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -528,16 +528,6 @@ end

function allocate_metrics(grid::LatitudeLongitudeGrid)
FT = eltype(grid)

# preallocate quantities to ensure correct type and size
grid_metrics = (:Δxᶠᶜ,
:Δxᶜᶠ,
:Δxᶠᶠ,
:Δxᶜᶜ,
:Azᶠᶜ,
:Azᶜᶠ,
:Azᶠᶠ,
:Azᶜᶜ)

arch = grid.architecture

Expand All @@ -549,14 +539,17 @@ function allocate_metrics(grid::LatitudeLongitudeGrid)
metric_size = (length(grid.Δλᶜᵃᵃ) , length(grid.φᵃᶜᵃ))
simone-silvestri marked this conversation as resolved.
Show resolved Hide resolved
end

for metric in grid_metrics
parentM = Symbol(metric, :_parent)
@eval $parentM = zeros($FT, $metric_size...)
@eval $metric = OffsetArray(on_architecture($arch, $parentM), $offsets...)
end
Δxᶠᶜ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I am questioning the use of eval from the beginning :)

You were defining new global variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was the purpose of the @eval?

Δxᶜᶠ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)
Δxᶠᶠ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)
Δxᶜᶜ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)
Azᶠᶜ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)
Azᶜᶠ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)
Azᶠᶠ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)
Azᶜᶜ = OffsetArray(zeros(FT, arch, metric_size...), offsets...)

if grid isa YRegularLLG
Δyᶠᶜ = FT(0.0)
Δyᶠᶜ = FT(0)
Δyᶜᶠ = FT(0.0)
simone-silvestri marked this conversation as resolved.
Show resolved Hide resolved
else
parentC = zeros(FT, length(grid.Δφᵃᶜᵃ))
Expand Down