Skip to content

Commit f7cf6a2

Browse files
authored
Fix reconstruct_global_grid (#4157)
1 parent 3abd9f6 commit f7cf6a2

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

src/DistributedComputations/distributed_grids.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,21 @@ const DistributedGrid{FT, TX, TY, TZ} = AbstractGrid{FT, TX, TY, TZ, <:Distribut
1616
const DistributedRectilinearGrid{FT, TX, TY, TZ, CZ, FX, FY, VX, VY} =
1717
RectilinearGrid{FT, TX, TY, TZ, CZ, FX, FY, VX, VY, <:Distributed} where {FT, TX, TY, TZ, CZ, FX, FY, VX, VY}
1818

19-
const DistributedLatitudeLongitudeGrid{FT, TX, TY, TZ, CZ, M, MY, FX, FY, VX, VY} =
20-
LatitudeLongitudeGrid{FT, TX, TY, TZ, CZ, M, MY, FX, FY, VX, VY, <:Distributed} where {FT, TX, TY, TZ, CZ, M, MY, FX, FY, VX, VY}
19+
const DistributedLatitudeLongitudeGrid{FT, TX, TY, TZ, Z,
20+
DXF, DXC, XF, XC,
21+
DYF, DYC, YF, YC,
22+
DXFC, DXCF, DXFF,
23+
DXCC, DYFC, DYCF} =
24+
LatitudeLongitudeGrid{FT, TX, TY, TZ, Z,
25+
DXF, DXC, XF, XC,
26+
DYF, DYC, YF, YC,
27+
DXFC, DXCF, DXFF,
28+
DXCC, DYFC, DYCF,
29+
<:Distributed} where {FT, TX, TY, TZ, Z,
30+
DXF, DXC, XF, XC,
31+
DYF, DYC, YF, YC,
32+
DXFC, DXCF, DXFF,
33+
DXCC, DYFC, DYCF}
2134

2235
# Local size from global size and architecture
2336
local_size(arch::Distributed, global_sz) = (local_size(global_sz[1], arch.partition.x, arch.local_index[1]),

src/Grids/input_validation.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ function validate_halo(TX, TY, TZ, size, halo)
8484
halo = inflate_tuple(TX, TY, TZ, halo, default=0)
8585

8686
for i in 1:2
87-
!(halo[i] size[i]) && throw(ArgumentError("halo must be ≤ size for coordinate $(coordinate_name(i))"))
87+
H = halo[i]
88+
N = size[i]
89+
if !(H N)
90+
throw(ArgumentError("halo=$H must be ≤ size=$N for coordinate $(coordinate_name(i))"))
91+
end
8892
end
8993

9094
return halo

test/test_distributed_hydrostatic_model.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using MPI
77
# These tests are meant to be run on 4 ranks. This script may be run
88
# stand-alone (outside the test environment) via
99
#
10-
# mpiexec -n 4 julia --project test_distributed_models.jl
10+
# $ MPI_TEST=true mpiexec -n 4 julia --project test_distributed_hydrostatic_model.jl
1111
#
1212
# provided that a few packages (like TimesDates.jl) are in your global environment.
1313
#
@@ -17,14 +17,10 @@ using MPI
1717
#
1818
# then later:
1919
#
20-
# julia> include("test_distributed_models.jl")
21-
#
22-
# When running the tests this way, uncomment the following line
20+
# julia> include("test_distributed_hydrostatic_model.jl")
2321

2422
MPI.Initialized() || MPI.Init()
2523

26-
# to initialize MPI.
27-
2824
using Oceananigans.Operators: hack_cosd
2925
using Oceananigans.DistributedComputations: ranks, partition, all_reduce, cpu_architecture, reconstruct_global_grid, synchronized
3026
using Oceananigans.TurbulenceClosures.TKEBasedVerticalDiffusivities: CATKEVerticalDiffusivity
@@ -86,7 +82,7 @@ Nx = 32
8682
Ny = 32
8783

8884
for arch in archs
89-
85+
9086
# We do not test on `Fractional` partitions where we cannot easily ensure that H ≤ N
9187
# which would lead to different advection schemes for partitioned and non-partitioned grids.
9288
# `Fractional` is, however, tested in regression tests where the horizontal dimensions are larger.
@@ -96,23 +92,25 @@ for arch in archs
9692

9793
if valid_x_partition & valid_y_partition & valid_z_partition
9894
@testset "Testing distributed solid body rotation" begin
99-
underlying_grid = LatitudeLongitudeGrid(arch, size = (Nx, Ny, 3),
95+
underlying_grid = LatitudeLongitudeGrid(arch,
96+
size = (Nx, Ny, 3),
10097
halo = (4, 4, 3),
10198
latitude = (-80, 80),
10299
longitude = (-160, 160),
103100
z = (-1, 0),
104101
radius = 1,
105-
topology=(Bounded, Bounded, Bounded))
102+
topology = (Bounded, Bounded, Bounded))
106103

107104
bottom(λ, φ) = -30 < λ < 30 && -40 < φ < 20 ? 0 : - 1
108105

109106
immersed_grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom))
110-
immersed_active_grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom); active_cells_map = true)
107+
immersed_active_grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom); active_cells_map=true)
111108

112109
global_underlying_grid = reconstruct_global_grid(underlying_grid)
113110
global_immersed_grid = ImmersedBoundaryGrid(global_underlying_grid, GridFittedBottom(bottom))
114111

115-
for (grid, global_grid) in zip((underlying_grid, immersed_grid, immersed_active_grid), (global_underlying_grid, global_immersed_grid, global_immersed_grid))
112+
for (grid, global_grid) in zip((underlying_grid, immersed_grid, immersed_active_grid),
113+
(global_underlying_grid, global_immersed_grid, global_immersed_grid))
116114
if arch.local_rank == 0
117115
@info " Testing distributed solid body rotation with $(ranks(arch)) ranks on $(typeof(grid).name.wrapper)"
118116
end
@@ -190,3 +188,4 @@ for arch in archs
190188
end
191189
end
192190
end
191+

test/test_distributed_models.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@ using MPI
1818
# then later:
1919
#
2020
# julia> include("test_distributed_models.jl")
21-
#
22-
# When running the tests this way, uncomment the following line
2321

2422
MPI.Init()
2523

26-
# to initialize MPI.
27-
2824
using Oceananigans.BoundaryConditions: fill_halo_regions!, DCBC
2925
using Oceananigans.DistributedComputations: Distributed, index2rank
3026
using Oceananigans.Fields: AbstractField

0 commit comments

Comments
 (0)