diff --git a/config/default_configs/default_config.yml b/config/default_configs/default_config.yml index c2dc754d462..de782846b8c 100644 --- a/config/default_configs/default_config.yml +++ b/config/default_configs/default_config.yml @@ -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 diff --git a/src/solver/type_getters.jl b/src/solver/type_getters.jl index 27b178f2f61..e1016fb00db 100644 --- a/src/solver/type_getters.jl +++ b/src/solver/type_getters.jl @@ -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,