Skip to content

Commit a6e6fee

Browse files
Merge pull request #50 from ChrisRackauckas-Claude/precompile-improvements-20260107-154605
Add precompilation workload to improve TTFX
2 parents b880d52 + 4c2437a commit a6e6fee

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ CommonSolve = "38540f10-b2f7-11e9-35d8-d573e4eb0ff2"
88
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
99
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
1010
OrdinaryDiffEqCore = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
11+
OrdinaryDiffEqLowOrderRK = "1344f307-1e59-4825-a18e-ace9aa3fa4c6"
12+
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1113
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
1214
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
1315
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
@@ -22,6 +24,7 @@ ModelingToolkit = "10"
2224
OrdinaryDiffEqCore = "1.19.0, 2"
2325
OrdinaryDiffEqLowOrderRK = "1.7"
2426
OrdinaryDiffEqTsit5 = "1.1.0"
27+
PrecompileTools = "1.0"
2528
RecursiveArrayTools = "3.39.0"
2629
SafeTestsets = "0.1.0"
2730
SciMLBase = "2.77.0"
@@ -32,10 +35,9 @@ julia = "1.10"
3235
[extras]
3336
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
3437
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
35-
OrdinaryDiffEqLowOrderRK = "1344f307-1e59-4825-a18e-ace9aa3fa4c6"
3638
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
3739
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
3840
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3941

4042
[targets]
41-
test = ["ExplicitImports", "ModelingToolkit", "OrdinaryDiffEqLowOrderRK", "OrdinaryDiffEqTsit5", "SafeTestsets", "Test"]
43+
test = ["ExplicitImports", "ModelingToolkit", "OrdinaryDiffEqTsit5", "SafeTestsets", "Test"]

src/OrdinaryDiffEqOperatorSplitting.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ include("utils.jl")
2727

2828
export GenericSplitFunction, OperatorSplittingProblem, LieTrotterGodunov
2929

30+
include("precompilation.jl")
31+
3032
end

src/precompilation.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using PrecompileTools: @compile_workload
2+
using OrdinaryDiffEqLowOrderRK: Euler
3+
4+
function _precompile_ode1(du, u, p, t)
5+
return @. du = -0.1u
6+
end
7+
8+
function _precompile_ode2(du, u, p, t)
9+
du[1] = -0.01u[2]
10+
return du[2] = -0.01u[1]
11+
end
12+
13+
@compile_workload begin
14+
# Setup minimal test problem for precompilation
15+
tspan = (0.0, 0.1)
16+
u0 = [1.0, 1.0, 1.0]
17+
18+
f1 = DiffEqBase.ODEFunction(_precompile_ode1)
19+
f2 = DiffEqBase.ODEFunction(_precompile_ode2)
20+
21+
f1dofs = [1, 2, 3]
22+
f2dofs = [1, 3]
23+
fsplit = GenericSplitFunction((f1, f2), (f1dofs, f2dofs))
24+
25+
prob = OperatorSplittingProblem(fsplit, u0, tspan)
26+
tstepper = LieTrotterGodunov((Euler(), Euler()))
27+
28+
# Precompile init and a few steps
29+
integrator = DiffEqBase.init(prob, tstepper, dt = 0.01, verbose = false)
30+
DiffEqBase.step!(integrator)
31+
DiffEqBase.solve!(integrator)
32+
end

0 commit comments

Comments
 (0)