Skip to content

Commit

Permalink
Add warn_allocations_diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Dec 1, 2023
1 parent ca07075 commit 4927afa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,6 @@ output_default_diagnostics:
netcdf_interpolate_z_over_msl:
help: "Interpolate diagnostics in the NetCDF files in such a way that `z` is the elevation from the sea level (as opposed to the elevation from the surface)"
value: false
warn_allocations_diagnostics:
help: "When true, a dry-run for all the diagnostics is perform to check whether the functions allocate additional memory (which reduces performances)"
value: true
17 changes: 17 additions & 0 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,23 @@ function get_simulation(config::AtmosConfig)
end
@info "Init diagnostics: $s"

if config.parsed_args["warn_allocations_diagnostics"]
for diag in diagnostics_iterations
# We write over the storage space we have already prepared (and filled) before
allocs = @allocated diag.variable.compute!(
diagnostic_storage[diag],
integrator.u,
integrator.p,
integrator.t,
)
if allocs > 10 * 1024
@warn "Diagnostics $(diag.output_short_name) allocates $allocs bytes"
end
end
end

# Main.@exfiltrate

return AtmosSimulation(
sim_info.job_id,
sim_info.output_dir,
Expand Down

0 comments on commit 4927afa

Please sign in to comment.