-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
506 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using OrthogonalSphericalShellGrids | ||
using Oceananigans | ||
using MPI | ||
MPI.Init() | ||
|
||
include("test/distributed_tests_utils.jl") | ||
arch = Distributed(CPU(), partition = Partition(2, 2)) | ||
|
||
distributed_grid = TripolarGrid(arch; size = (100, 100, 1), z = (-1000, 0)) | ||
distributed_grid = mask_singularities(distributed_grid) | ||
|
||
simulation = run_tripolar_simulation(distributed_grid) | ||
|
||
if arch.local_rank == 0 | ||
η = reconstruct_global_field(simulation.model.free_surface.η) | ||
u = reconstruct_global_field(simulation.model.velocities.u) | ||
v = reconstruct_global_field(simulation.model.velocities.v) | ||
|
||
fill_halo_regions!(η) | ||
fill_halo_regions!(u) | ||
fill_halo_regions!(v) | ||
jldsave("distributed_tripolar.jld2"; η = η.data, u = u.data, v = v.data) | ||
end | ||
|
||
MPI.Barrier(MPI.COMM_WORLD) | ||
MPI.Finalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using Oceananigans.BoundaryConditions: fill_open_boundary_regions!, | ||
permute_boundary_conditions, | ||
fill_halo_event!, | ||
DistributedCommunication | ||
|
||
using Oceananigans.DistributedComputations: cooperative_waitall!, | ||
recv_from_buffers!, | ||
fill_corners!, | ||
loc_id, | ||
DCBCT | ||
|
||
import Oceananigans.BoundaryConditions: fill_halo_regions! | ||
import Oceananigans.DistributedComputations: synchronize_communication! | ||
|
||
@inline instantiate(T::DataType) = T() | ||
@inline instantiate(T) = T | ||
|
||
const DistributedZipper = BoundaryCondition{<:DistributedCommunication, <:ZipperHaloCommunicationRanks} | ||
|
||
switch_north_halos!(c, north_bc, grid, loc) = nothing | ||
|
||
function switch_north_halos!(c, north_bc::DistributedZipper, grid, loc) | ||
sign = north_bc.condition.sign | ||
Hy = halo_size(grid)[2] | ||
Ny = size(grid)[2] | ||
sz = size(parent(c)) | ||
|
||
_switch_north_halos!(parent(c), loc, sign, sz, Ny, Hy) | ||
|
||
return nothing | ||
end | ||
|
||
# We throw away the first point! | ||
_switch_north_halos!(c, ::Tuple{<:Center, <:Center, <:Any}, sign, sz, Ny, Hy) = | ||
view(c, :, Ny+Hy+1:Ny+2Hy-1, :) .= sign .* reverse(view(c, :, Ny+2Hy:-1:Ny+Hy+2, :), dims = 1) | ||
|
||
# We do not throw away the first point! | ||
_switch_north_halos!(c, ::Tuple{<:Center, <:Face, <:Any}, sign, sz, Ny, Hy) = | ||
view(c, :, Ny+Hy+1:Ny+2Hy, :) .= sign .* reverse(view(c, :, Ny+2Hy:-1:Ny+Hy+1, :), dims = 1) | ||
|
||
# We throw away the first line and the first point! | ||
_switch_north_halos!(c, ::Tuple{<:Face, <:Center, <:Any}, sign, (Px, Py, Pz), Ny, Hy) = | ||
view(c, 2:Px, Ny+Hy+1:Ny+2Hy-1, :) .= sign .* reverse(view(c, 2:Px, Ny+2Hy:-1:Ny+Hy+2, :), dims = 1) | ||
|
||
# We throw away the first line but not the first point! | ||
_switch_north_halos!(c, ::Tuple{<:Face, <:Face, <:Any}, sign, (Px, Py, Pz), Ny, Hy) = | ||
view(c, 2:Px, Ny+Hy+1:Ny+2Hy, :) .= sign .* reverse(view(c, 2:Px, Ny+2Hy:-1:Ny+Hy+1, :), dims = 1) | ||
|
||
function fill_halo_regions!(c::OffsetArray, bcs, indices, loc, grid::DTRG, buffers, args...; only_local_halos = false, fill_boundary_normal_velocities = true, kwargs...) | ||
if fill_boundary_normal_velocities | ||
fill_open_boundary_regions!(c, bcs, indices, loc, grid, args...; kwargs...) | ||
end | ||
|
||
north_bc = bcs.north | ||
|
||
arch = architecture(grid) | ||
fill_halos!, bcs = permute_boundary_conditions(bcs) | ||
|
||
number_of_tasks = length(fill_halos!) | ||
|
||
for task = 1:number_of_tasks | ||
fill_halo_event!(c, fill_halos![task], bcs[task], indices, loc, arch, grid, buffers, args...; only_local_halos, kwargs...) | ||
end | ||
|
||
fill_corners!(c, arch.connectivity, indices, loc, arch, grid, buffers, args...; only_local_halos, kwargs...) | ||
|
||
# We increment the tag counter only if we have actually initiated the MPI communication. | ||
# This is the case only if at least one of the boundary conditions is a distributed communication | ||
# boundary condition (DCBCT) _and_ the `only_local_halos` keyword argument is false. | ||
increment_tag = any(isa.(bcs, DCBCT)) && !only_local_halos | ||
|
||
if increment_tag | ||
arch.mpi_tag[] += 1 | ||
end | ||
|
||
switch_north_halos!(c, north_bc, grid, loc) | ||
|
||
return nothing | ||
end | ||
|
||
function synchronize_communication!(field::Field{<:Any, <:Any, <:Any, <:Any, <:DTRG}) | ||
arch = architecture(field.grid) | ||
|
||
# Wait for outstanding requests | ||
if !isempty(arch.mpi_requests) | ||
cooperative_waitall!(arch.mpi_requests) | ||
|
||
# Reset MPI tag | ||
arch.mpi_tag[] = 0 | ||
|
||
# Reset MPI requests | ||
empty!(arch.mpi_requests) | ||
end | ||
|
||
recv_from_buffers!(field.data, field.boundary_buffers, field.grid) | ||
|
||
north_bc = field.boundary_conditions.north | ||
instantiated_location = map(instantiate, location(field)) | ||
|
||
switch_north_halos!(field, north_bc, field.grid, instantiated_location) | ||
|
||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import Oceananigans.DistributedComputations: north_recv_tag, | ||
north_send_tag, | ||
northwest_recv_tag, | ||
northwest_send_tag, | ||
northeast_recv_tag, | ||
northeast_send_tag | ||
|
||
ID_DIGITS = 2 | ||
|
||
sides = (:west, :east, :south, :north, :southwest, :southeast, :northwest, :northeast) | ||
side_id = Dict(side => n-1 for (n, side) in enumerate(sides)) | ||
|
||
# Change these and we are golden! | ||
function north_recv_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "8" : string(side_id[:south]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function north_send_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "8" : string(side_id[:north]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northwest_recv_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "9" : string(side_id[:southeast]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northwest_send_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "9" : string(side_id[:northwest]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northeast_recv_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "10" : string(side_id[:southwest]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end | ||
|
||
function northeast_send_tag(arch, ::DTRG, location) | ||
field_id = string(arch.mpi_tag[], pad=ID_DIGITS) | ||
loc_digit = string(loc_id(location...), pad=ID_DIGITS) | ||
last_rank = arch.local_index[2] == ranks(arch)[2] | ||
side_digit = last_rank ? "10" : string(side_id[:northeast]) | ||
return parse(Int, field_id * loc_digit * side_digit) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using OrthogonalSphericalShellGrids | ||
using Oceananigans | ||
using Oceananigans.Grids: halo_size | ||
using Oceananigans.Utils | ||
using Oceananigans.BoundaryConditions | ||
using OrthogonalSphericalShellGrids: get_cartesian_nodes_and_vertices | ||
using Oceananigans.CUDA | ||
using Test | ||
|
||
using KernelAbstractions: @kernel, @index | ||
|
||
arch = CUDA.has_cuda_gpu() ? GPU() : CPU() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Oceananigans | ||
using Oceananigans.Units | ||
|
||
function run_tripolar_simulation(grid) | ||
|
||
model = HydrostaticFreeSurfaceModel(; grid = grid, | ||
free_surface = SplitExplicitFreeSurface(grid; substeps = 20), | ||
tracers = (), | ||
buoyancy = nothing, | ||
momentum_advection = VectorInvariant(), | ||
coriolis = HydrostaticSphericalCoriolis()) | ||
|
||
# Setup the model with a gaussian profile near the physical north poles | ||
ηᵢ(λ, φ, z) = exp(- (φ - 90)^2 / 10^2) | ||
|
||
set!(model, η = ηᵢ) | ||
|
||
simulation = Simulation(model, Δt = 1minutes, stop_iteration = 100) | ||
|
||
run!(simulation) | ||
|
||
return simulation | ||
end | ||
|
||
function mask_singularities(underlying_grid) | ||
λp = underlying_grid.conformal_mapping.first_pole_longitude | ||
φp = underlying_grid.conformal_mapping.north_poles_latitude | ||
|
||
# We need a bottom height field that ``masks'' the singularities | ||
bottom_height(λ, φ) = ((abs(λ - λp) < 5) & (abs(φp - φ) < 5)) | | ||
((abs(λ - λp - 180) < 5) & (abs(φp - φ) < 5)) | (φ < -80) ? 0 : - 1000 | ||
|
||
grid = ImmersedBoundaryGrid(underlying_grid, GridFittedBottom(bottom_height)) | ||
|
||
return grid | ||
end |
Oops, something went wrong.