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

Add Y-partition and XY-partition tests #3338

Merged
merged 127 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
bb10cae
partitioning
simone-silvestri Oct 10, 2023
c679d88
ready for regression
simone-silvestri Oct 10, 2023
34e07a5
mutable
simone-silvestri Oct 10, 2023
fd8e099
remove topology from arch
simone-silvestri Oct 10, 2023
de1177d
fix topology issue
simone-silvestri Oct 10, 2023
9a87593
no need to regularize connectivity
simone-silvestri Oct 10, 2023
e40dfe6
comments
simone-silvestri Oct 10, 2023
8c5bf7f
some bugfixxes
simone-silvestri Oct 10, 2023
a2165ca
more bug fixing
simone-silvestri Oct 10, 2023
9831b7e
one bug down
simone-silvestri Oct 10, 2023
492d376
fix indent
simone-silvestri Oct 10, 2023
28b4293
bugfix
simone-silvestri Oct 10, 2023
2855375
fixed tests
simone-silvestri Oct 10, 2023
1cd66f7
fixed tests
simone-silvestri Oct 11, 2023
527a246
bugifx
simone-silvestri Oct 11, 2023
7ca0e40
bugfix
simone-silvestri Oct 11, 2023
7b632bc
bugfix
simone-silvestri Oct 11, 2023
ce75461
fixed tests
simone-silvestri Oct 11, 2023
c88901d
downloading correct data
simone-silvestri Oct 11, 2023
f8edf35
another test
simone-silvestri Oct 11, 2023
3952535
last debuggging to follow
simone-silvestri Oct 11, 2023
394d593
bounded regression to fix
simone-silvestri Oct 11, 2023
1fb7d3f
test on caltech cluster
simone-silvestri Oct 11, 2023
cbc20c2
test correct files
simone-silvestri Oct 11, 2023
b43f1fc
correct keys
simone-silvestri Oct 11, 2023
7f5d8dc
remove tracer advection test
simone-silvestri Oct 11, 2023
029f8f9
forgot delta_min
simone-silvestri Oct 11, 2023
8d182cb
fix
simone-silvestri Oct 11, 2023
10779a6
using types
simone-silvestri Oct 11, 2023
098da36
now it should work
simone-silvestri Oct 11, 2023
bc1876b
add all tests
simone-silvestri Oct 11, 2023
34a3b93
last bugfix
simone-silvestri Oct 11, 2023
37588c0
fix cpu_architecture
simone-silvestri Oct 11, 2023
c15c7bd
everything ready
simone-silvestri Oct 11, 2023
fabf5ec
bugfix in tests
simone-silvestri Oct 11, 2023
68a15a5
need to have the same dt!
simone-silvestri Oct 11, 2023
a9ea1f2
Make sure we always use the same dt
simone-silvestri Oct 11, 2023
0d9af26
typo
simone-silvestri Oct 11, 2023
1147eff
typo
simone-silvestri Oct 11, 2023
4c723b1
now finally all should be solved
simone-silvestri Oct 11, 2023
18593b2
last all_reduce?
simone-silvestri Oct 11, 2023
4fe12c6
another small bugfix
simone-silvestri Oct 11, 2023
d45fd61
small fix
simone-silvestri Oct 12, 2023
b8f55fb
another fix
simone-silvestri Oct 12, 2023
51c33fe
added a barrier!
simone-silvestri Oct 12, 2023
eb127eb
take off y-partition
simone-silvestri Oct 12, 2023
9b836a8
some suggestions
simone-silvestri Oct 12, 2023
5b929c2
corrected isbits error
simone-silvestri Oct 12, 2023
82cb425
change all_reduce to mirror mapreduce
simone-silvestri Oct 12, 2023
239a914
Update test/utils_for_runtests.jl
glwagner Oct 12, 2023
8e49769
Update src/DistributedComputations/halo_communication_bcs.jl
glwagner Oct 12, 2023
b1a6cf8
Update test/test_distributed_hydrostatic_model.jl
glwagner Oct 12, 2023
83acd08
Update test/test_distributed_hydrostatic_model.jl
glwagner Oct 12, 2023
1e4603c
Update test/regression_tests/hydrostatic_free_turbulence_regression_t…
navidcy Oct 12, 2023
3d5b59c
probaly found it
simone-silvestri Oct 12, 2023
252596d
test all
simone-silvestri Oct 12, 2023
10c17f3
Merge branch 'ss/distributed_tests' of github.com:CliMA/Oceananigans.…
simone-silvestri Oct 12, 2023
905c9f5
just one D
simone-silvestri Oct 12, 2023
bd8ff0d
only x partitioning
simone-silvestri Oct 13, 2023
d4839e5
all suggestions applied
simone-silvestri Oct 13, 2023
503caee
try now
simone-silvestri Oct 13, 2023
22906b6
Merge remote-tracking branch 'origin/main' into ss/distributed_tests
simone-silvestri Oct 13, 2023
76bb1cf
bugfix
simone-silvestri Oct 13, 2023
0768236
missing comma
simone-silvestri Oct 13, 2023
b5d8271
woops
simone-silvestri Oct 13, 2023
043577e
radius was missing
simone-silvestri Oct 13, 2023
7225835
this was the bug?
simone-silvestri Oct 13, 2023
b0cb434
deadlock on xy partitioning for the moment
simone-silvestri Oct 13, 2023
9e9838e
fixed hydrostatic test
simone-silvestri Oct 15, 2023
153699a
try it now
simone-silvestri Oct 15, 2023
b82a315
adjusted buffers
simone-silvestri Oct 15, 2023
5df9e82
try ot like this
simone-silvestri Oct 15, 2023
f7aadc8
bugfix
simone-silvestri Oct 15, 2023
e6bc508
bugfix
simone-silvestri Oct 15, 2023
f8b9ff7
small bugfix
simone-silvestri Oct 15, 2023
af5ca07
Multiregion correction
simone-silvestri Oct 15, 2023
631bd55
other fix
simone-silvestri Oct 15, 2023
ffe0587
check this
simone-silvestri Oct 15, 2023
b91ad6d
I think this was the problem
simone-silvestri Oct 15, 2023
42615a8
remove implicit test and fix lat lon tests
simone-silvestri Oct 15, 2023
297f8ac
modify test for c
simone-silvestri Oct 15, 2023
2679b01
change signature
simone-silvestri Oct 15, 2023
0182c47
multiregion quick change
simone-silvestri Oct 15, 2023
93aef1d
was missing it here
simone-silvestri Oct 15, 2023
1eac677
better comment
simone-silvestri Oct 15, 2023
ef56339
test it here
simone-silvestri Oct 15, 2023
1e2b88d
ok try it like this
simone-silvestri Oct 15, 2023
356fefc
old grids back
simone-silvestri Oct 15, 2023
c2ef14c
bugfix
simone-silvestri Oct 16, 2023
a7aa982
Merge branch 'ss/distributed_tests' of github.com:CliMA/Oceananigans.…
simone-silvestri Oct 16, 2023
13842e7
back to gaussian
simone-silvestri Oct 16, 2023
6133f96
another bugfix
simone-silvestri Oct 16, 2023
5d71626
xy partitioning
simone-silvestri Oct 16, 2023
678367c
small correction
simone-silvestri Oct 16, 2023
ea30d4a
change test
simone-silvestri Oct 16, 2023
f031285
comment
simone-silvestri Oct 16, 2023
b7d6682
fixing multiregion
simone-silvestri Oct 16, 2023
47fe139
fix multi-region
simone-silvestri Oct 16, 2023
74264b3
relax test for distributed
simone-silvestri Oct 16, 2023
1d9cd7e
small change
simone-silvestri Oct 16, 2023
85c8d5e
regenerated data
simone-silvestri Oct 16, 2023
7d7c265
test it now
simone-silvestri Oct 16, 2023
3ebfeb8
add split explicit to the mix?
simone-silvestri Oct 16, 2023
1583db5
fixed the multi region
simone-silvestri Oct 17, 2023
5d72592
try it like this for the moment
simone-silvestri Oct 17, 2023
d041a12
revert multiregion BC util we figure it out
simone-silvestri Oct 17, 2023
a7e09f0
increase node memory
simone-silvestri Oct 17, 2023
919f336
Merge branch 'ss/distributed_tests' of github.com:CliMA/Oceananigans.…
simone-silvestri Oct 17, 2023
0d910d2
everything works
simone-silvestri Oct 17, 2023
81f58f4
ready to go
simone-silvestri Oct 17, 2023
b7fc0b9
fix some comments
simone-silvestri Oct 17, 2023
b9ac378
Update src/BoundaryConditions/fill_halo_regions_periodic.jl
simone-silvestri Oct 23, 2023
af98014
Update src/DistributedComputations/halo_communication_bcs.jl
simone-silvestri Oct 23, 2023
af8450f
Update src/DistributedComputations/halo_communication.jl
simone-silvestri Oct 23, 2023
f1bbd6a
fixing halo tuple stuff
simone-silvestri Oct 23, 2023
854a019
some comments
simone-silvestri Oct 23, 2023
b637c37
comment
simone-silvestri Oct 23, 2023
e8c457f
fixed also multiregion
simone-silvestri Oct 23, 2023
996d20e
bugfix
simone-silvestri Oct 23, 2023
b0859df
some changes
simone-silvestri Oct 23, 2023
0cbc9c3
fixed all tests
simone-silvestri Oct 23, 2023
58a0159
alignment
simone-silvestri Oct 23, 2023
6743956
change function signature
simone-silvestri Oct 23, 2023
085f855
comment
simone-silvestri Oct 23, 2023
c4ce430
switch to "free_surface_grid"
simone-silvestri Oct 24, 2023
1d13ce4
remove vestigial code
simone-silvestri Oct 24, 2023
9a59d8f
Merge branch 'main' into ss/distributed_tests
glwagner Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .buildkite/distributed/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ steps:
- "julia --project -e 'using Pkg; Pkg.status()'"

agents:
slurm_mem: 80G
slurm_mem: 120G
slurm_gpus: 1
slurm_cpus_per_task: 8
env:
Expand All @@ -52,6 +52,7 @@ steps:
commands:
- "srun julia -O0 --color=yes --project -e 'using Pkg; Pkg.test()'"
agents:
slurm_mem: 120G
slurm_ntasks: 4
slurm_gpus_per_task: 1

Expand Down Expand Up @@ -80,6 +81,7 @@ steps:
commands:
- "srun julia -O0 --color=yes --project -e 'using Pkg; Pkg.test()'"
agents:
slurm_mem: 120G
slurm_ntasks: 4
slurm_gpus_per_task: 1

Expand Down
208 changes: 150 additions & 58 deletions src/BoundaryConditions/fill_halo_regions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,27 @@ conditions, possibly recursing into `fields` if it is a nested tuple-of-tuples.
# Some fields have `nothing` boundary conditions, such as `FunctionField` and `ZeroField`.
fill_halo_regions!(c::OffsetArray, ::Nothing, args...; kwargs...) = nothing

# Returns the boundary conditions a specific side for `FieldBoundaryConditions` inputs and
# a tuple of boundary conditions for `NTuple{N, <:FieldBoundaryConditions}` inputs
for dir in (:west, :east, :south, :north, :bottom, :top)
extract_bc = Symbol(:extract_, dir, :_bc)
extract_side_bc = Symbol(:extract_, dir, :_bc)
@eval begin
@inline $extract_bc(bc) = bc.$dir
@inline $extract_bc(bc::Tuple) = map($extract_bc, bc)
@inline $extract_side_bc(bc) = bc.$dir
@inline $extract_side_bc(bc::Tuple) = map($extract_side_bc, bc)
end
end
#
@inline extract_bc(bc, ::Val{:west}) = tuple(extract_west_bc(bc))
@inline extract_bc(bc, ::Val{:east}) = tuple(extract_east_bc(bc))
@inline extract_bc(bc, ::Val{:south}) = tuple(extract_south_bc(bc))
@inline extract_bc(bc, ::Val{:north}) = tuple(extract_north_bc(bc))
@inline extract_bc(bc, ::Val{:bottom}) = tuple(extract_bottom_bc(bc))
@inline extract_bc(bc, ::Val{:top}) = tuple(extract_top_bc(bc))

@inline extract_bc(bc, ::Val{:west_and_east}) = (extract_west_bc(bc), extract_east_bc(bc))
@inline extract_bc(bc, ::Val{:south_and_north}) = (extract_south_bc(bc), extract_north_bc(bc))
@inline extract_bc(bc, ::Val{:bottom_and_top}) = (extract_bottom_bc(bc), extract_top_bc(bc))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's all this for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case we have a tuple of FieldBoundaryConditions instead of just one FieldBoundaryConditions where we can just do (bc.west, bc.east)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, so this will extract a "tuple of west bcs" and a "tuple of east bcs".

Can you write that in a comment?


# For inhomogeneous BC we extract the _last_ one
# example
# `bc.west <: DCBC`
# `bc.east <: PBC`
# `extract_west_or_east_bc(bc) == bc.west`
# NOTE that `isless` follows order of execution,
# so `max(bcs...)` returns the last BC to execute

extract_west_or_east_bc(bc) = max(bc.west, bc.east)
extract_south_or_north_bc(bc) = max(bc.south, bc.north)
extract_bottom_or_top_bc(bc) = max(bc.bottom, bc.top)

extract_west_or_east_bc(bc::Tuple) = map(extract_west_or_east_bc, bc)
extract_south_or_north_bc(bc::Tuple) = map(extract_south_or_north_bc, bc)
extract_bottom_or_top_bc(bc::Tuple) = map(extract_bottom_or_top_bc, bc)

# Finally, the true fill_halo!
const MaybeTupledData = Union{OffsetArray, NTuple{<:Any, OffsetArray}}

Expand All @@ -53,63 +50,95 @@ function fill_halo_regions!(c::MaybeTupledData, boundary_conditions, indices, lo

arch = architecture(grid)

halo_tuple = permute_boundary_conditions(boundary_conditions)
fill_halos!, bcs = permute_boundary_conditions(boundary_conditions)
number_of_tasks = length(fill_halos!)

# Fill halo in the three permuted directions (1, 2, and 3), making sure dependencies are fulfilled
for task in 1:3
fill_halo_event!(task, halo_tuple, c, indices, loc, arch, grid, args...; kwargs...)
for task = 1:number_of_tasks
fill_halo_event!(c, fill_halos![task], bcs[task], indices, loc, arch, grid, args...; kwargs...)
end

return nothing
end

function fill_halo_event!(task, halo_tuple, c, indices, loc, arch, grid, args...; kwargs...)
fill_halo! = halo_tuple[1][task]
bc_left = halo_tuple[2][task]
bc_right = halo_tuple[3][task]
function fill_halo_event!(c, fill_halos!, bcs, indices, loc, arch, grid, args...; kwargs...)

# Calculate size and offset of the fill_halo kernel
size = fill_halo_size(c, fill_halo!, indices, bc_left, loc, grid)
offset = fill_halo_offset(size, fill_halo!, indices)
# We assume that the kernel size is the same for west and east boundaries,
# south and north boundaries, and bottom and top boundaries
size = fill_halo_size(c, fill_halos!, indices, bcs[1], loc, grid)
offset = fill_halo_offset(size, fill_halos!, indices)

fill_halos!(c, bcs..., size, offset, loc, arch, grid, args...; kwargs...)

fill_halo!(c, bc_left, bc_right, size, offset, loc, arch, grid, args...; kwargs...)
return nothing
end

# In case of a DistributedCommunication paired with a
# Flux, Value or Gradient boundary condition, we split the direction in two single-sided
# fill_halo! events (see issue #3342)
# `permute_boundary_conditions` returns a 2-tuple containing the ordered operations to execute in
# position [1] and the associated boundary conditions in position [2]
function permute_boundary_conditions(boundary_conditions)

split_x_boundaries = split_boundary(extract_west_bc(boundary_conditions), extract_east_bc(boundary_conditions))
split_y_boundaries = split_boundary(extract_south_bc(boundary_conditions), extract_north_bc(boundary_conditions))

fill_x_side_halo! = split_x_boundaries ? (fill_west_halo!, fill_east_halo!) : tuple(fill_west_and_east_halo!)
fill_y_side_halo! = split_y_boundaries ? (fill_south_halo!, fill_north_halo!) : tuple(fill_south_and_north_halo!)

west_bc = extract_west_bc(boundary_conditions)
east_bc = extract_east_bc(boundary_conditions)
south_bc = extract_south_bc(boundary_conditions)
north_bc = extract_north_bc(boundary_conditions)

x_side_bcs = split_x_boundaries ? (west_bc, east_bc) : tuple(west_bc)
y_side_bcs = split_y_boundaries ? (south_bc, north_bc) : tuple(south_bc)

x_sides = split_x_boundaries ? (:west, :east) : tuple(:west_and_east)
y_sides = split_y_boundaries ? (:south, :north) : tuple(:south_and_north)

fill_halos! = [
fill_west_and_east_halo!,
fill_south_and_north_halo!,
fill_bottom_and_top_halo!,
fill_x_side_halo!...,
fill_y_side_halo!...,
fill_bottom_and_top_halo! # bottom and top cannot be Distributed so never split them
]

boundary_conditions_array = [
extract_west_or_east_bc(boundary_conditions),
extract_south_or_north_bc(boundary_conditions),
extract_bottom_or_top_bc(boundary_conditions)
sides = [
x_sides...,
y_sides...,
:bottom_and_top
]

boundary_conditions_array_left = [
extract_west_bc(boundary_conditions),
extract_south_bc(boundary_conditions),
bcs_array = [
x_side_bcs...,
y_side_bcs...,
extract_bottom_bc(boundary_conditions)
]

boundary_conditions_array_right = [
extract_east_bc(boundary_conditions),
extract_north_bc(boundary_conditions),
extract_top_bc(boundary_conditions),
]

perm = sortperm(boundary_conditions_array, lt=fill_first)
perm = sortperm(bcs_array, lt=fill_first)
fill_halos! = fill_halos![perm]
boundary_conditions_array_left = boundary_conditions_array_left[perm]
boundary_conditions_array_right = boundary_conditions_array_right[perm]
sides = sides[perm]

boundary_conditions = Tuple(extract_bc(boundary_conditions, Val(side)) for side in sides)

return (fill_halos!, boundary_conditions_array_left, boundary_conditions_array_right)
return fill_halos!, boundary_conditions
end

# Split direction in two distinct fill_halo! events in case of a communication boundary condition
# (distributed DCBC), paired with a Flux, Value or Gradient boundary condition
split_boundary(bcs1, bcs2) = false
split_boundary(::DCBC, ::DCBC) = false
split_boundary(bcs1, ::DCBC) = true
split_boundary(::DCBC, bcs2) = true

# TODO: support heterogeneous distributed-shared communication
# split_boundary(::MCBC, ::DCBC) = false
# split_boundary(::DCBC, ::MCBC) = false
# split_boundary(::MCBC, ::MCBC) = false
# split_boundary(bcs1, ::MCBC) = true
# split_boundary(::MCBC, bcs2) = true

#####
##### Halo filling order
#####
Expand All @@ -118,11 +147,16 @@ const PBCT = Union{PBC, NTuple{<:Any, <:PBC}}
const MCBCT = Union{MCBC, NTuple{<:Any, <:MCBC}}
const DCBCT = Union{DCBC, NTuple{<:Any, <:DCBC}}

# Distributed halos have to be filled for last in case of
# buffered communication. Hence, we always fill them last
# Distributed halos have to be filled last to allow the
# possibility of asynchronous communication:
# If other halos are filled after we initiate the distributed communication,
# (but before communication is completed) the halos will be overwritten.
# For this reason we always want to perform local halo filling first and then
# initiate communication

# The reasoning for filling Periodic after Flux, Value, Gradient
# Periodic is handled after Flux, Value, Gradient because
glwagner marked this conversation as resolved.
Show resolved Hide resolved
# Periodic fills also corners while Flux, Value, Gradient do not
# TODO: remove this ordering requirement (see issue https://github.com/CliMA/Oceananigans.jl/issues/3342)

# Order of halo filling
# 1) Flux, Value, Gradient (TODO: remove these BC and apply them as fluxes)
Expand Down Expand Up @@ -160,7 +194,7 @@ fill_first(bc1::MCBCT, bc2::MCBCT) = true
fill_first(bc1, bc2) = true

#####
##### General fill_halo! kernels
##### Double-sided fill_halo! kernels
#####

@kernel function _fill_west_and_east_halo!(c, west_bc, east_bc, loc, grid, args)
Expand All @@ -182,9 +216,45 @@ end
end

#####
##### Tuple fill_halo! kernels
##### Single-sided fill_halo! kernels
#####

@kernel function _fill_only_west_halo!(c, bc, loc, grid, args)
j, k = @index(Global, NTuple)
_fill_west_halo!(j, k, grid, c, bc, loc, args...)
end

@kernel function _fill_only_south_halo!(c, bc, loc, grid, args)
i, k = @index(Global, NTuple)
_fill_south_halo!(i, k, grid, c, bc, loc, args...)
end

@kernel function _fill_only_bottom_halo!(c, bc, loc, grid, args)
i, j = @index(Global, NTuple)
_fill_bottom_halo!(i, j, grid, c, bc, loc, args...)
end

@kernel function _fill_only_east_halo!(c, bc, loc, grid, args)
j, k = @index(Global, NTuple)
_fill_east_halo!(j, k, grid, c, bc, loc, args...)
end

@kernel function _fill_only_north_halo!(c, bc, loc, grid, args)
i, k = @index(Global, NTuple)
_fill_north_halo!(i, k, grid, c, bc, loc, args...)
end

@kernel function _fill_only_top_halo!(c, bc, loc, grid, args)
i, j = @index(Global, NTuple)
_fill_top_halo!(i, j, grid, c, bc, loc, args...)
end

#####
##### Tupled double-sided fill_halo! kernels
#####

# Note, we do not need tupled single-sided fill_halo! kernels since `DCBC` do not
# support tupled halo filling
import Oceananigans.Utils: @constprop

@kernel function _fill_west_and_east_halo!(c::NTuple, west_bc, east_bc, loc, grid, args)
Expand Down Expand Up @@ -223,6 +293,27 @@ end
end
end

#####
##### Kernel launchers for single-sided fill_halos
#####

fill_west_halo!(c, bc, size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(size, offset), _fill_only_west_halo!, c, bc, loc, grid, Tuple(args); kwargs...)
fill_east_halo!(c, bc, size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(size, offset), _fill_only_east_halo!, c, bc, loc, grid, Tuple(args); kwargs...)
fill_south_halo!(c, bc, size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(size, offset), _fill_only_south_halo!, c, bc, loc, grid, Tuple(args); kwargs...)
fill_north_halo!(c, bc, size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(size, offset), _fill_only_north_halo!, c, bc, loc, grid, Tuple(args); kwargs...)
fill_bottom_halo!(c, bc, size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(size, offset), _fill_only_bottom_halo!, c, bc, loc, grid, Tuple(args); kwargs...)
fill_top_halo!(c, bc, size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(size, offset), _fill_only_top_halo!, c, bc, loc, grid, Tuple(args); kwargs...)

#####
##### Kernel launchers for double-sided fill_halos
#####

fill_west_and_east_halo!(c, west_bc, east_bc, size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(size, offset), _fill_west_and_east_halo!, c, west_bc, east_bc, loc, grid, Tuple(args); kwargs...)

Expand All @@ -236,9 +327,9 @@ fill_bottom_and_top_halo!(c, bottom_bc, top_bc, size, offset, loc, arch, grid, a
##### Calculate kernel size and offset for Windowed and Sliced Fields
#####

const WEB = typeof(fill_west_and_east_halo!)
const SNB = typeof(fill_south_and_north_halo!)
const TBB = typeof(fill_bottom_and_top_halo!)
const WEB = Union{typeof(fill_west_and_east_halo!), typeof(fill_west_halo!), typeof(fill_east_halo!)}
const SNB = Union{typeof(fill_south_and_north_halo!), typeof(fill_south_halo!), typeof(fill_north_halo!)}
const TBB = Union{typeof(fill_bottom_and_top_halo!), typeof(fill_bottom_halo!), typeof(fill_top_halo!)}

# Tupled halo filling _only_ deals with full fields!
@inline fill_halo_size(::Tuple, ::WEB, args...) = :yz
Expand Down Expand Up @@ -278,3 +369,4 @@ const TBB = typeof(fill_bottom_and_top_halo!)
@inline fill_halo_offset(::Tuple, ::WEB, idx) = (idx[2] == Colon() ? 0 : first(idx[2])-1, idx[3] == Colon() ? 0 : first(idx[3])-1)
@inline fill_halo_offset(::Tuple, ::SNB, idx) = (idx[1] == Colon() ? 0 : first(idx[1])-1, idx[3] == Colon() ? 0 : first(idx[3])-1)
@inline fill_halo_offset(::Tuple, ::TBB, idx) = (idx[1] == Colon() ? 0 : first(idx[1])-1, idx[2] == Colon() ? 0 : first(idx[2])-1)

52 changes: 0 additions & 52 deletions src/BoundaryConditions/fill_halo_regions_flux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,55 +33,3 @@ using KernelAbstractions.Extras.LoopInfo: @unroll
@inline _fill_north_halo!(i, k, grid, c, ::FBC, args...) = _fill_flux_north_halo!(i, 1, k, grid, c)
@inline _fill_bottom_halo!(i, j, grid, c, ::FBC, args...) = _fill_flux_bottom_halo!(i, j, 1, grid, c)
@inline _fill_top_halo!(i, j, grid, c, ::FBC, args...) = _fill_flux_top_halo!(i, j, 1, grid, c)

#####
##### Single halo filling kernels
#####

@kernel function fill_flux_west_halo!(c, grid)
j, k = @index(Global, NTuple)
_fill_flux_west_halo!(1, j, k, grid, c)
end

@kernel function fill_flux_south_halo!(c, grid)
i, k = @index(Global, NTuple)
_fill_flux_south_halo!(i, 1, k, grid, c)
end

@kernel function fill_flux_bottom_halo!(c, grid)
i, j = @index(Global, NTuple)
_fill_flux_bottom_halo!(i, j, 1, grid, c)
end

@kernel function fill_flux_east_halo!(c, grid)
j, k = @index(Global, NTuple)
_fill_flux_east_halo!(1, j, k, grid, c)
end

@kernel function fill_flux_north_halo!(c, grid)
i, k = @index(Global, NTuple)
_fill_flux_north_halo!(i, 1, k, grid, c)
end

@kernel function fill_flux_top_halo!(c, grid)
i, j = @index(Global, NTuple)
_fill_flux_top_halo!(i, j, 1, grid, c)
end

#####
##### Kernel launchers for flux boundary conditions
#####

fill_west_halo!(c, bc::FBC, kernel_size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(kernel_size, offset), fill_flux_west_halo!, c,grid; kwargs...)
fill_east_halo!(c, bc::FBC, kernel_size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(kernel_size, offset), fill_flux_east_halo!, c, grid; kwargs...)
fill_south_halo!(c, bc::FBC, kernel_size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(kernel_size, offset), fill_flux_south_halo!, c, grid; kwargs...)
fill_north_halo!(c, bc::FBC, kernel_size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(kernel_size, offset), fill_flux_north_halo!, c, grid; kwargs...)
fill_bottom_halo!(c, bc::FBC, kernel_size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(kernel_size, offset), fill_flux_bottom_halo!, c, grid; kwargs...)
fill_top_halo!(c, bc::FBC, kernel_size, offset, loc, arch, grid, args...; kwargs...) =
launch!(arch, grid, KernelParameters(kernel_size, offset), fill_flux_top_halo!, c, grid; kwargs...)

11 changes: 11 additions & 0 deletions src/BoundaryConditions/fill_halo_regions_periodic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,14 @@ end
end
end
end

#####
##### Throw error if single-sided periodic boundary conditions are used
#####

fill_west_halo!(c, ::PBCT, args...; kwargs...) = throw(ArgumentError("Periodic boundary conditions must be applied to both sides"))
fill_east_halo!(c, ::PBCT, args...; kwargs...) = throw(ArgumentError("Periodic boundary conditions must be applied to both sides"))
fill_south_halo!(c, ::PBCT, args...; kwargs...) = throw(ArgumentError("Periodic boundary conditions must be applied to both sides"))
fill_north_halo!(c, ::PBCT, args...; kwargs...) = throw(ArgumentError("Periodic boundary conditions must be applied to both sides"))
fill_bottom_halo!(c, ::PBCT, args...; kwargs...) = throw(ArgumentError("Periodic boundary conditions must be applied to both sides"))
fill_top_halo!(c, ::PBCT, args...; kwargs...) = throw(ArgumentError("Periodic boundary conditions must be applied to both sides"))
Loading