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

Allow interpolation on Distributed architectures #3499

Merged
merged 9 commits into from
Mar 25, 2024
8 changes: 8 additions & 0 deletions src/Fields/interpolate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using Oceananigans.Grids: topology, node,
ZRegOrthogonalSphericalShellGrid,
RectilinearGrid, LatitudeLongitudeGrid

using Oceananigans.Architectures: child_architecture

# GPU-compatile middle point calculation
@inline middle_point(l, h) = Base.unsafe_trunc(Int, (l + h) / 2)

Expand Down Expand Up @@ -313,6 +315,12 @@ function interpolate!(to_field::Field, from_field::AbstractField)

to_arch = architecture(to_field)
from_arch = architecture(from_field)

# In case architectures are `Distributed` we
# verify that the fields are on the same child architecture
to_arch = child_architecture(to_arch)
from_arch = child_architecture(from_arch)

if !isnothing(from_arch) && to_arch != from_arch
msg = "Cannot interpolate! because from_field is on $from_arch while to_field is on $to_arch."
throw(ArgumentError(msg))
Expand Down
2 changes: 1 addition & 1 deletion test/test_distributed_hydrostatic_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Ny = 32
for arch in archs
@testset "Testing distributed solid body rotation" begin
grid = LatitudeLongitudeGrid(arch, size = (Nx, Ny, 1),
halo = (3, 3, 3),
halo = (4, 4, 4),
latitude = (-80, 80),
longitude = (-160, 160),
z = (-1, 0),
Expand Down