-
Notifications
You must be signed in to change notification settings - Fork 194
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
Massive clean up for conditional operations #3794
base: main
Are you sure you want to change the base?
Conversation
Here's an example: using Oceananigans
Nx, Ny, Nz = 100, 100, 100
latitude = longitude = z = (0, 1)
underlying_grid = LatitudeLongitudeGrid(size=(Nx, Ny, Nz); latitude, longitude, z)
grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom((λ, φ) -> 0.5))
ci = CenterField(grid)
ciw = view(ci, 1:Nx, 1:Ny, 1:Nz)
cu = CenterField(underlying_grid)
cuw = view(cu, 1:Nx, 1:Ny, 1:Nz)
for n = 1:10
@time minimum(ci)
@time minimum(ciw)
@time minimum(cu)
@time minimum(cuw)
end Previously reducing The basic lesson is to use explicit dispatch with type-based information, rather than using functions like |
AUUUGHHH that was hard but finally found the source of the type instability: Oceananigans.jl/src/AbstractOperations/AbstractOperations.jl Lines 37 to 44 in 4dbec26
( fixing that finally made the difference. Just required generalizing the one we already have for Oceananigans.jl/src/Fields/field.jl Lines 401 to 413 in 4dbec26
|
which type instability; is this related to discussion in #3750? |
Yes. That issue documents slow reductions for windowed fields on immersed boundary grids. I hypothesized that it was due to a failure of type inference. Looking into it further I see that |
It's not really a bug btw |
But definitely clean up and performance. Just to clarify fixing type inference doesn't change the result of the reduction, it just makes it go much faster |
Was OOO last week but can review this later today! This PR does resolve the slowness in #3750! julia> @time minimum(u2)
0.059865 seconds (665 allocations: 54.930 KiB)
0.0
julia> @time minimum(u2.data)
0.011223 seconds (3 allocations: 1.562 KiB)
0.0 Some overhead which is expected I think, but way better than 2000x slower lol. |
@ali-ramadhan let's focus first on #3801 and then we can revisit this PR. There are some additional challenges to resolving #3791 unfortunately that will also require some test refactoring. |
This PR greatly simplifies the logic behind
conditional_operation
and how its extended for immersd boundary grid. The end result besides source code clean up seems to be an improvement in type inference.Resolves #3750 I think. But @ali-ramadhan please test.
EDIT: I decided not to work on #3791 (here) because this requires fixing a bunch of tests and is a bigger effort.