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

Benchmarking forcing functions #370

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Changes from all commits
Commits
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
73 changes: 73 additions & 0 deletions benchmark/benchmark_forcing_functions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using TimerOutputs, Printf

using Oceananigans

const timer = TimerOutput()

Ni = 2 # Number of iterations before benchmarking starts.
Nt = 10 # Number of iterations to use for benchmarking time stepping.

# Run benchmark across these parameters.
Ns = [(128, 128, 128)]
float_types = [Float64] # Float types to benchmark.
archs = [CPU()] # Architectures to benchmark on.
@hascuda archs = [GPU()] # Benchmark GPU on systems with CUDA-enabled GPUs.

arch_name(::String) = ""
arch_name(::CPU) = "CPU"
arch_name(::GPU) = "GPU"

function benchmark_name(N, id, arch, FT; npad=2)
Nx, Ny, Nz = N

bn = ""
bn *= lpad(Nx, npad, " ") * "×" * lpad(Ny, npad, " ") * "×" * lpad(Nz, npad, " ")
bn *= " $id"

arch = arch_name(arch)
bn *= " ($arch, $FT)"

return bn
end

benchmark_name(N, id) = benchmark_name(N, id, "", "", "")

@inline function Fu(grid, U, Φ, i, j, k)
if k == 1
return @inbounds -2*0.1/grid.Δz^2 * (U.u[i, j, 1] - 0)
elseif k == grid.Nz
return @inbounds -2*0.1/grid.Δz^2 * (U.u[i, j, grid.Nz] - 0)
else
return 0
end
end

@inline FT(grid, U, Φ, i, j, k) = @inbounds ifelse(k == 1, -1e-4 * (Φ.T[i, j, 1] - 0), 0)
forcing = Forcing(Fu=Fu, FT=FT)

for arch in archs, float_type in float_types, N in Ns
Nx, Ny, Nz = N
Lx, Ly, Lz = 1, 1, 1

forced_model = Model(N=(Nx, Ny, Nz), L=(Lx, Ly, Lz), arch=arch, float_type=float_type, forcing=forcing)
time_step!(forced_model, Ni, 1) # First 1-2 iterations usually slower.

bn = benchmark_name(N, "with forcing", arch, float_type)
@printf("Running benchmark: %s...\n", bn)
for i in 1:Nt
@timeit timer bn time_step!(forced_model, 1, 1)
end

unforced_model = Model(N=(Nx, Ny, Nz), L=(Lx, Ly, Lz), arch=arch, float_type=float_type)
time_step!(unforced_model, Ni, 1) # First 1-2 iterations usually slower.

bn = benchmark_name(N, " no forcing", arch, float_type)
@printf("Running benchmark: %s...\n", bn)
for i in 1:Nt
@timeit timer bn time_step!(unforced_model, 1, 1)
end
end

print_timer(timer, title="Forcing function benchmarks")
println("")