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

Test allocations #139

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Expand Down
43 changes: 22 additions & 21 deletions test/test_Density.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Test, GeoParams, StaticArrays
using Test, GeoParams, StaticArrays, AllocCheck

@testset "Density.jl" begin

Expand Down Expand Up @@ -51,31 +51,27 @@ using Test, GeoParams, StaticArrays
args = (P=P, T=T)

x = ConstantDensity()
num_alloc = @allocated compute_density!(rho, x, args)
num_alloc = @allocated compute_density!(rho, x, args)
# @show num_alloc
# @test num_alloc == 0

num_alloc = check_allocs(compute_density!, typeof.((rho, x, args)))
@test isempty(num_alloc)

#Test allocations using ρ alias
ρ!(rho, x, args)
num_alloc = @allocated ρ!(rho, x, args)
# @test num_alloc == 0
num_alloc = check_allocs(ρ!, typeof.((rho, x, args)))
@test isempty(num_alloc)

# This does NOT allocate if I test this with @btime;
# yet it does while running the test here
x = PT_Density()
compute_density!(rho, x, args)
num_alloc = @allocated compute_density!(rho, x, args)
# @show num_alloc
# @test num_alloc ≤ 32
num_alloc = check_allocs(compute_density!, typeof.((rho, x, args)))
@test isempty(num_alloc)

# This does NOT allocate if I test this with @btime;
# yet it does while running the test here
x = Compressible_Density()
compute_density!(rho, x, args)
num_alloc = @allocated compute_density!(rho, x, args)
# @show num_alloc
# @test num_alloc ≤ 32
num_alloc = check_allocs(compute_density!, typeof.((rho, x, args)))
@test isempty(num_alloc)

# Read Phase diagram interpolation object
fname = "test_data/Peridotite_dry.in"
Expand Down Expand Up @@ -184,16 +180,19 @@ using Test, GeoParams, StaticArrays

# Test computing density when Mat_tup1 is provided as a tuple
compute_density!(rho, Mat_tup1, Phases, args)
num_alloc = @allocated compute_density!(rho, Mat_tup1, Phases, args) # 287.416 μs (0 allocations: 0 bytes)
num_alloc = check_allocs(compute_density!, typeof.((rho, Mat_tup1, Phases, args))) # 287.416 μs (0 allocations: 0 bytes)
@test isempty(num_alloc)

@test sum(rho) / 400^2 ≈ 2945.000013499999
# @test num_alloc ≤ 32
@test isempty(num_alloc)

#Same test using function alias
rho = zeros(size(Phases))
ρ!(rho, Mat_tup1, Phases, args)
num_alloc = @allocated compute_density!(rho, Mat_tup1, Phases, args)
num_alloc = check_allocs(compute_density!, typeof.((rho, Mat_tup1, Phases, args)))
@test isempty(num_alloc)
compute_density!(rho, Mat_tup1, Phases, args)
@test sum(rho) / 400^2 ≈ 2945.000013499999
# @test num_alloc ≤ 32

# Test for single phase
compute_density(MatParam, 1, (P=P[1], T=T[1]))
Expand All @@ -211,10 +210,12 @@ using Test, GeoParams, StaticArrays
end

compute_density!(rho, Mat_tup1, PhaseRatio, args)

num_alloc = @allocated compute_density!(rho, Mat_tup1, PhaseRatio, args) # 136.776 μs (0 allocations: 0 bytes)
@test sum(rho) / 400^2 ≈ 2945.000013499999
# @test num_alloc ≤ 32 # for some reason this does indicate allocations but @btime does not

# num_alloc = check_allocs(compute_density!, typeof.((rho, Mat_tup1, PhaseRatio, args))) # 136.776 μs (0 allocations: 0 bytes)
# @test isempty(num_alloc) # for some reason this does indicate allocations but @btime does not
num_alloc = @allocated compute_density!(rho, Mat_tup1, PhaseRatio, args)
@test iszero(num_alloc) # for some reason this does indicate allocations but @btime does not

# Test calling the routine with only pressure as input.
# This is ok for Mat_tup1, as it only has constant & P-dependent densities.
Expand Down
27 changes: 15 additions & 12 deletions test/test_Energy.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Test
using GeoParams
using Test, GeoParams, AllocCheck

@testset "EnergyParameters.jl" begin

Expand Down Expand Up @@ -95,9 +94,10 @@ using GeoParams
compute_heatcapacity!(Cp, Mat_tup1, Phases, args1) # computation routine w/out P (not used in most heat capacity formulations)
@test sum(Cp[1, 1, :]) ≈ 109050.0

num_alloc = @allocated compute_heatcapacity!(Cp, Mat_tup, Phases, args)
compute_heatcapacity!(Cp, Mat_tup, Phases, args)
@test sum(Cp[1, 1, :]) ≈ 121399.0486067196
# @test num_alloc <= 32
num_alloc = check_allocs(compute_heatcapacity!, typeof.((Cp, Mat_tup, Phases, args)))
@test isempty(num_alloc)

# test if we provide phase ratios
PhaseRatio = zeros(n, n, n, 3)
Expand All @@ -107,9 +107,10 @@ using GeoParams
PhaseRatio[I] = 1.0
end
compute_heatcapacity!(Cp, Mat_tup, PhaseRatio, args)
num_alloc = @allocated compute_heatcapacity!(Cp, Mat_tup, PhaseRatio, args)
@test sum(Cp[1, 1, :]) ≈ 121399.0486067196
# @test num_alloc <= 32
# num_alloc = check_allocs(compute_heatcapacity!, typeof.((Cp, Mat_tup, PhaseRatio, args)))
num_alloc = @allocated compute_heatcapacity!(Cp, Mat_tup, PhaseRatio, args)
@test iszero(num_alloc)

# -----------------------

Expand Down Expand Up @@ -221,13 +222,15 @@ using GeoParams

compute_conductivity!(k, Mat_tup, Phases, args)
@test sum(k) ≈ 1.9216938849389635e6
# num_alloc = @allocated compute_conductivity!(k, Mat_tup, Phases, args)
# @test num_alloc <= 32
# num_alloc = check_allocs(compute_conductivity!, typeof.((k, Mat_tup, Phases, args)))
num_alloc = @allocated compute_conductivity!(k, Mat_tup, Phases, args)
@test iszero(num_alloc)

compute_conductivity!(k, Mat_tup, PhaseRatio, args)
@test sum(k) ≈ 1.9216938849389635e6
# num_alloc = @allocated compute_conductivity!(k, Mat_tup, PhaseRatio, args)
# @test num_alloc <= 32
# num_alloc = check_allocs(compute_conductivity!, typeof.((k, Mat_tup, PhaseRatio, args)))
num_alloc = @allocated compute_conductivity!(k, Mat_tup, PhaseRatio, args)
@test iszero(num_alloc)

######

Expand Down Expand Up @@ -370,8 +373,8 @@ using GeoParams
compute_radioactive_heat!(Hr, Mat_tup1, Phases, args1)
@test Hr[50, 50, 50] ≈ 1e-6

# num_alloc = @allocated compute_radioactive_heat!(Hr, Mat_tup, Phases, args)
# @test num_alloc <= 32 # in the commandline this gives 0; while running the script not always
num_alloc = check_allocs(compute_radioactive_heat!, typeof.((Hr, Mat_tup, Phases, args)))
@test isempty(num_alloc) # in the commandline this gives 0; while running the script not always

compute_radioactive_heat!(Hr, Mat_tup, PhaseRatio, args)
@test sum(Hr) ≈ 0.33715177646857664
Expand Down
8 changes: 4 additions & 4 deletions test/test_Plasticity.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Test
using GeoParams
using Test, GeoParams, AllocCheck

@testset "Plasticity.jl" begin

Expand Down Expand Up @@ -78,9 +77,10 @@ using GeoParams
PhaseRatio[I] = 1.0
end
compute_yieldfunction!(F, MatParam, PhaseRatio, args)
num_alloc = @allocated compute_yieldfunction!(F, MatParam, PhaseRatio, args)
@test maximum(F[1, 1, :]) ≈ 839745.962155614
# @test num_alloc <= 32
# num_alloc = check_allocs(compute_yieldfunction!, typeof.((F, MatParam, PhaseRatio, args)))
num_alloc = @allocated compute_yieldfunction!(F, MatParam, PhaseRatio, args)
@test iszero(num_alloc)

# Test plastic potential derivatives
## 2D
Expand Down
Loading