Open ali-ramadhan opened 2 weeks ago
I thought this might be an issue with Field
s themselves, but no:
using Oceananigans
arch = CPU()
L = 1
H = 1
underlying_grid = LatitudeLongitudeGrid(
arch;
topology = (Bounded, Bounded, Bounded),
size = (512, 512, 64),
latitude = (-L/2, L/2),
longitude = (-L/2, L/2),
z = (-H, 0),
halo = (4, 4, 4)
)
h = L/2
w = L/5
mount(x, y) = h * exp(-x^2 / 2w^2) * exp(-y^2 / 2w^2)
bottom(x, y) = -H + mount(x, y)
grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))
model = HydrostaticFreeSurfaceModel(; grid)
u = model.velocities.u
then
julia> @time minimum(u)
0.063563 seconds (344 allocations: 31.789 KiB)
0.0
julia> @time minimum(u.data)
0.013262 seconds (3 allocations: 1.391 KiB)
0.0
Only ~6x slower.
So maybe the FieldTimeSeries
is creating the field from u[2]
differently?
I haven't looked into the code much but wanted to at least open this issue.
Reductions on FieldTimeSeries are performed individually for each element by constructing two Fields and reducing one into another. Probably, the construction of the individual field is what is causing the loss in performance?
We do not necessarily need to do that, we can just wrap the data in a ConditionalOperation
.
Just a thought that we probably want reductions on field time series to be performant anyways. So it's better that we call data summary because then more people will be annoyed that they are slow => more pressure to fix it š
This also makes
data_summary
andBase.show
very slow since showing aFieldTimeSeries
prints its min, mean, and max. So it's harder to work withFieldTimeSeries
interactively. Seems fine when not on aImmersedBoundaryGrid
.I'm guessing it's slower because it's masking out the immersed values but I don't know if we expect it to be ~2000x slower than without an immersed boundary. It's those memory allocations...
A quick quality-of-life fix could be to not call
data_summary
when showing aFieldTimeSeries
.MWE
Reduction over the
FieldTimeSeries
:Reduction over the underlying data:
or almost 2000x faster.
Environment
Oceananigans.jl
main
branch with