Skip to content

Commit

Permalink
Add precompilation (#48)
Browse files Browse the repository at this point in the history
* Add precompilation; drop Requires

* Update benchmarks
  • Loading branch information
henry2004y authored Jun 9, 2024
1 parent 697332c commit 4053437
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name = "FieldTracer"
uuid = "05065131-34d1-456a-ba22-faf972bb2934"
authors = ["Hongyang Zhou <hyzhou@umich.edu>"]
version = "0.1.14"
version = "0.1.15"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
MuladdMacro = "46d2c3a1-f734-5fdb-9937-b9b9aeba4221"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
Meshes = "0.44"
MuladdMacro = "0.2"
Requires = "1.1"
PrecompileTools = "1"
julia = "1.6"

[extras]
Expand Down
15 changes: 8 additions & 7 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SUITE["trace"]["2D structured"] = BenchmarkGroup()
SUITE["trace"]["3D structured"] = BenchmarkGroup()

# Euler2 and RK4 functions
ds, maxstep = 0.1, 150
ds, maxstep = 0.1, 100
x = range(0, 1, step=0.1)
y = range(0, 1, step=0.1)
# ndgrid
Expand All @@ -22,10 +22,12 @@ xstart = 0.1
ystart = 0.9

SUITE["trace"]["2D structured"]["euler"] =
@benchmarkable FieldTracer.euler($maxstep, $ds, $xstart, $ystart, $x, $y, $u, $v)
@benchmarkable trace($u, $v, $xstart, $ystart, $x, $y;
alg=Euler(), ds=$ds, maxstep=$maxstep)

SUITE["trace"]["2D structured"]["rk4"] =
@benchmarkable FieldTracer.rk4($maxstep, $ds, $xstart, $ystart, $x, $y, $u, $v)
@benchmarkable trace($u, $v, $xstart, $ystart, $x, $y;
alg=RK4(), ds=$ds, maxstep=$maxstep)

x = range(0, 10, length=15)
y = range(0, 10, length=20)
Expand All @@ -36,8 +38,7 @@ bz = fill(1.0, length(x), length(y), length(z))
xs, ys, zs = 1.0, 1.0, 1.0

SUITE["trace"]["3D structured"]["euler"] =
@benchmarkable trace($bx, $bz, $bz, $xs, $ys, $zs, $x, $y, $z;
alg=Euler(), ds=0.2, maxstep=200)
@benchmarkable trace($bx, $by, $bz, $xs, $ys, $zs, $x, $y, $z;
alg=Euler(), ds=$ds, maxstep=$maxstep)
SUITE["trace"]["3D structured"]["rk4"] =
@benchmarkable trace($bx, $by, $bz, $xs, $ys, $zs, $x, $y, $z;
ds=0.2, maxstep=200, direction="forward")
@benchmarkable trace($bx, $by, $bz, $xs, $ys, $zs, $x, $y, $z; ds=$ds, maxstep=$maxstep)
5 changes: 4 additions & 1 deletion src/FieldTracer.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module FieldTracer

using Meshes, Requires, MuladdMacro
using Meshes, MuladdMacro
using PrecompileTools: @setup_workload, @compile_workload

export trace
export Euler, RK4
Expand Down Expand Up @@ -48,4 +49,6 @@ function trace(args...; alg::Algorithm=RK4(), kwargs...)

end

include("precompile.jl")

end
37 changes: 37 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Precompiling workloads

@setup_workload begin
@compile_workload begin
x = range(0, 1, step=0.1)
y = range(0, 1, step=0.1)
# ndgrid
u, v = let
xgrid = [i for i in x, _ in y]
ygrid = [j for _ in x, j in y]
copy(xgrid), -copy(ygrid)
end
xstart = 0.1
ystart = 0.9

#xt, yt = FieldTracer.euler(150, 0.1, 0.1, 0.9, x, y, u, v)
xt, yt = trace(u, v, xstart, ystart, x, y;
maxstep=100, ds=0.1, direction="both", alg=Euler())
xt, yt = trace(u, v, xstart, ystart, x, y;
maxstep=100, ds=0.1, direction="both", alg=RK4())

x = range(0, 10, length=10)
y = range(0, 10, length=10)
z = range(0, 10, length=10)
bx = fill(1.0, length(x), length(y), length(z))
by = fill(1.0, length(x), length(y), length(z))
bz = fill(1.0, length(x), length(y), length(z))
xs, ys, zs = 1.0, 1.0, 1.0

# Euler 2nd order
x1, y1, z1 = trace(bx, by, bz, xs, ys, zs, x, y, z;
maxstep=10, ds=0.2, direction="both", alg=Euler())
# RK4
x1, y1, z1 = trace(bx, by, bz, xs, ys, zs, x, y, z;
maxstep=10, ds=0.2, direction="both", alg=RK4())
end
end

2 comments on commit 4053437

@henry2004y
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/108595

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.15 -m "<description of version>" 4053437e97c6fa213c0a76a61b438f7dcc742759
git push origin v0.1.15

Please sign in to comment.