Skip to content

Correctness test for update_hydrostatic_pressure! #97

@glwagner

Description

@glwagner

Here's a correctness test for a single kernel (update_hydrostatic_pressure!)

using Oceananigans
using Oceananigans.Architectures: ReactantState
using Reactant
using Statistics

function simple_model(arch)
    Nx = Nz = 16
    grid = RectilinearGrid(arch, size=(Nx, 1, Nz), x=(-Nx/2, Nx/2), y=(0, 1), z=(0, Nz))
    free_surface = ExplicitFreeSurface()
    model = HydrostaticFreeSurfaceModel(; grid, free_surface, buoyancy=BuoyancyTracer(), tracers=:b)
    bᵢ(x, y, z) = exp(-x^2)
    set!(model, b=bᵢ)
    return model
end

c_model = simple_model(CPU())
r_model = simple_model(Oceananigans.Architectures.ReactantState())

using Oceananigans.Models.NonhydrostaticModels: update_hydrostatic_pressure!

c_p = c_model.pressure.pHY′
r_p = r_model.pressure.pHY′
@time update_hydrostatic_pressure!(c_p, CPU(), c_model.grid, c_model.buoyancy, c_model.tracers)

r_update_hydrostatic_pressure! = @compile(
    sync = true,
    raise = true,
    update_hydrostatic_pressure!(
        r_p,
        ReactantState(),
        r_model.grid,
        r_model.buoyancy,
        r_model.tracers
    )
)

@time r_update_hydrostatic_pressure!(r_p, ReactantState(), r_model.grid, r_model.buoyancy, r_model.tracers)

pc = c_model.pressure.pHY′
pr = r_model.pressure.pHY′

pcp = interior(pc, :, :, 1)
pcr = Array(interior(pr, :, :, 1))

@show maximum(abs, pcp .- pcr)

gives

julia> include("mwe.jl")
  0.001675 seconds (1.46 k allocations: 116.469 KiB, 91.55% compilation time)
  0.011373 seconds (48.76 k allocations: 3.376 MiB, 99.31% compilation time)
maximum(abs, pcp .- pcr) = 0.38940039153570183
0.38940039153570183

My status

(GordonBell25) pkg> st
Project GordonBell25 v0.1.0
Status `~/Projects/GB-25/Project.toml`
  [6e4b80f9] BenchmarkTools v1.6.0
  [179af706] CFTime v0.1.4
  [0376089a] ClimaOcean v0.5.6
  [9e8cae18] Oceananigans v0.96.0 `https://github.com/CliMA/Oceananigans.jl.git#wm/ostracer`
  [aea7be01] PrecompileTools v1.2.1
  [3c362404] Reactant v0.2.47
  [efcf1570] Setfield v1.1.2
⌅ [0234f1f7] HDF5_jll v1.14.3+3
  [0192cb87] Reactant_jll v0.0.95+0
  [ade2ca70] Dates
  [de0858da] Printf
  [9abbd945] Profile
  [9a3f8284] Random
  [9e88b42a] Serialization

This result IS different than with Reactant_jll 0.0.94. I'm just guessing off the top of my head but I think the max discrepancy was ~12.

Metadata

Metadata

Assignees

No one assigned

    Labels

    correctnessMath is supposedly a thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions