Open
Description
I timed how long it takes to build and then take one time step with OceanSeaIceModel
with this script:
using Oceananigans
using ClimaOcean
using OrthogonalSphericalShellGrids
start_time = time_ns()
arch = GPU()
grid = TripolarGrid(arch;
size = (50, 50, 10),
halo = (7, 7, 7),
z = (-6000, 0),
first_pole_longitude = 75,
north_poles_latitude = 55)
bottom_height = retrieve_bathymetry(grid;
minimum_depth = 10,
dir = "./",
interpolation_passes = 20,
connected_regions_allowed = 0)
grid = ImmersedBoundaryGrid(grid, GridFittedBottom(bottom_height); active_cells_map = true)
elapsed = 1e-9 * (time_ns() - start_time)
@info "Grid / bathymetry construction time: " * prettytime(elapsed)
start_time = time_ns()
free_surface = SplitExplicitFreeSurface(grid; substeps = 20)
ocean = ocean_simulation(grid; free_surface)
model = ocean.model
@info "Ocean simulation construction time: " * prettytime(elapsed)
start_time = time_ns()
backend = JRA55NetCDFBackend(4)
atmosphere = JRA55_prescribed_atmosphere(arch; backend)
radiation = Radiation(arch)
elapsed = 1e-9 * (time_ns() - start_time)
@info "Atmosphere construction time: " * prettytime(elapsed)
# Fluxes are computed when the model is constructed, so we just test that this works.
start_time = time_ns()
sea_ice = ClimaOcean.OceanSeaIceModels.MinimumTemperatureSeaIce()
coupled_model = OceanSeaIceModel(ocean, sea_ice; atmosphere, radiation)
elapsed = 1e-9 * (time_ns() - start_time)
@info "Coupled model construction time: " * prettytime(elapsed)
start_time = time_ns()
time_step!(coupled_model, 1)
elapsed = 1e-9 * (time_ns() - start_time)
@info "One time step time: " * prettytime(elapsed)
Running for the first time I get (ignoring the annoying warnings mentioned on #133):
[ Info: Grid / bathymetry construction time: 1.839 minutes
[ Info: Ocean simulation construction time: 1.839 minutes
[ Info: Atmosphere construction time: 11.130 seconds
[ Info: Model construction time: 5.645 minutes
[ Info: One time step time: 17.764 seconds
The 6-minute wait time for model construction isn't alleviated until the 5th or 6th time building a model.
After the time-stepping is compiled, one time-step is considerably shorter:
julia> @time time_step!(coupled_model, 1)
0.036822 seconds (45.26 k allocations: 16.751 MiB)
It's not obvious to me why model construction is so expensive. We do call update_state!
within the model constructor, which computes fluxes. But this also has to be called during time_step!
, which is cheap. So there's something else going on.
Finally, time_step!
seems to allocate:
julia> @time for n = 1:100; time_step!(coupled_model, 1); end
2.330006 seconds (4.71 M allocations: 1.741 GiB, 2.54% gc time)
which is also problematic.