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

add temp field on boundary space to cache #584

Closed
juliasloan25 opened this issue Jan 31, 2024 · 0 comments · Fixed by #769
Closed

add temp field on boundary space to cache #584

juliasloan25 opened this issue Jan 31, 2024 · 0 comments · Fixed by #769
Assignees
Labels
🍃 leaf Issue coupled to a PR 💰 Grab Bag

Comments

@juliasloan25
Copy link
Member

juliasloan25 commented Jan 31, 2024

It might be useful to add a field to the cache where we can put temporary fields on the boundary space. For example, a land mask over the surface. This could prevent allocating new fields (masks) at each timestep.

We already have two fields defined on the boundary space: :temp1 and :temp2 in coupler_fields. We should use these more throughout the code where we're using fields for calculations but don't necessarily need to keep the field itself. Atmos also stores some temp fields in its cache, which we can use in functions accessing the AtmosSimulation.

Note: Fields.ones and Fields.zeros allocate a new field. parent and level both return views and do not allocate. axes also doesn't allocate, but creating a new field on the space returned by it would

places to use temp fields

  • import_combined_surface_fields
  • swap_space (double check that it allocates as it is now) - maybe we can change this to take in a space instead of calling axes(field). Then we won't have to create a field on a space just to access the space, e.g. in Regridder.land_fraction
  • calculate_surface_air_density for atmos
  • get_field(bucket_sim::BucketSimulation, ::Val{:energy})
  • check_conservation!(cc::WaterConservationCheck, coupler_sim::Interfacer.CoupledSimulation)
  • anything else using Fields.ones or Fields.zeros

Some useful findings

  • pointers
    @btime p.precomputed.ᶜts > 450.522 ns (4 allocations: 4.66 KiB)
  • operators
    @btime @. ᶜgradᵥ_.(ᶠinterp_(u.c.ρ)) > 16.212 μs (12 allocations: 120.62 KiB)
  • ...

notes:

  • import_combined_surface_fields!(): @btime FieldExchanger.import_combined_surface_fields!(cs.fields, cs.model_sims, cs.boundary_space, cs.turbulent_fluxes) 122.500 μs (207 allocations: 119.08 KiB) if all predefined: @btime FieldExchanger.import_combined_surface_fields!(fields, model_sims, boundary_space, turbulent_fluxes) 121.709 μs (200 allocations: 102.61 KiB)
    • using temp field reduced allocs from 209 -> 207
    • @btime Regridder.combine_surfaces!(combined_field, model_sims, Val(:surface_temperature)) 8.333 μs (28 allocations: 11.23 KiB)
      • @btime eltype(field1) 11.094 ns (0 allocations: 0 bytes)
      • @btime Interfacer.get_field(sim, Val(:area_fraction)) 54.272 ns (1 allocation: 32 bytes)
      • @btime nans_to_zero.(Interfacer.get_field(sim, field_name)) 1.467 μs (5 allocations: 12.39 KiB) (1 from get_field()).
    • @btime Regridder.dummmy_remap!(csf.T_S, combined_field) 290.280 ns (1 allocation: 32 bytes) vs @btime Regridder.dummmy_remap!(T_S, combined_field) 233.447 ns (0 allocations: 0 bytes
      • @btime parent(cs.fields.T_S) 338.352 ns (3 allocations: 3.73 KiB)
  • swap_space!(): @btime Utilities.swap_space!(cs.fields.temp1, cs.fields.temp2) 759.009 ns (7 allocations: 7.50 KiB) if fields preallocated: @btime Utilities.swap_space!(field1, field2) 56.968 ns (1 allocation: 32 bytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍃 leaf Issue coupled to a PR 💰 Grab Bag
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants