Skip to content

Commit

Permalink
speed a few kernels up and GC before testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisRackauckas committed Aug 21, 2020
1 parent 709b933 commit fc55f01
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
5 changes: 3 additions & 2 deletions Keller_Miksis_RK45/CPU_Julia/CPU_KellerMiksis_julia.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DifferentialEquations, DelimitedFiles, Plots, CPUTime
using DifferentialEquations, DelimitedFiles, Plots, CPUTime, MuladdMacro

const numberOfRuns = 3
const numberOfParameters = 256
Expand Down Expand Up @@ -63,7 +63,7 @@ end

#ensemble problem
function prob_func!(problem,i,repeat)
@inbounds begin
@inbounds @muladd begin
#calculating indexes
problem.u0[1] = initialValues[i,1]
problem.u0[2] = initialValues[i,2]
Expand Down Expand Up @@ -110,6 +110,7 @@ res = solve(
dense = false,
maxiters = 1e10,
dtmin = 1e-10)
GC.gc()

#solving ODE 3x and measuring elapsed CPU time
times = Vector{Float64}(undef,numberOfRuns)
Expand Down
1 change: 1 addition & 0 deletions Keller_Miksis_RK45/GPU_Julia/GPU_KellerMiksis_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ res = solve(
dense = false,
maxiters = 1e10,
dtmin = 1e-10)
GC.gc()

#solving ODE 3x and measuring elapsed CPU time
times = Vector{Float64}(undef,numberOfRuns)
Expand Down
14 changes: 7 additions & 7 deletions Lorenz_RK4/CPU_Julia/CPU_Lorenz_julia.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DifferentialEquations, CPUTime, Statistics
using DifferentialEquations, CPUTime, Statistics, MuladdMacro

#settings
const unroll = 128
Expand All @@ -17,12 +17,11 @@ end

#ODE
function lorenz!(du, u, p, t)
@inbounds for j in 1:unroll
index = 3(j-1)+1
du[index] = 10.0 * (u[index+1] - u[index])
du[index+1] = p[j] * u[index] - u[index+1] - u[index] * u[index+2]
du[index+2] = u[index] * u[index+1] - 2.66666666 * u[index+2]
end
@muladd @inbounds for j in 1:unroll
du[j] = 10.0 * (u[j+unroll] - u[j])
du[j+unroll] = p[j] * u[j] - u[j+unroll] - u[j] * u[j+2*unroll]
du[j+2*unroll] = u[j] * u[j+unroll] - 2.66666666 * u[j+2*unroll]
end
end

#compile
Expand All @@ -39,6 +38,7 @@ solve(
dt = 0.01,
unstable_check = nocheck
)
GC.gc()

#simulation
times = Vector{Float64}(undef,numberOfRuns)
Expand Down
14 changes: 7 additions & 7 deletions Lorenz_RK4/CPU_Julia/CPU_Lorenz_julia_ensemble.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DifferentialEquations, CPUTime, Statistics
using DifferentialEquations, CPUTime, Statistics, MuladdMacro

#settings
const unroll = 128
Expand All @@ -14,12 +14,11 @@ u0 = ones(3*unroll,1)*10

#ODE
function lorenz!(du, u, p, t)
@inbounds for j in 1:128
index = 3(j-1)+1
du[index] = 10.0 * (u[index+1] - u[index])
du[index+1] = p[j] * u[index] - u[index+1] - u[index] * u[index+2]
du[index+2] = u[index] * u[index+1] - 2.66666666 * u[index+2]
end
@muladd @inbounds for j in 1:unroll
du[j] = 10.0 * (u[j+unroll] - u[j])
du[j+unroll] = p[j] * u[j] - u[j+unroll] - u[j] * u[j+2*unroll]
du[j+2*unroll] = u[j] * u[j+unroll] - 2.66666666 * u[j+2*unroll]
end
end

#parameter change function
Expand Down Expand Up @@ -48,6 +47,7 @@ solve(
dense = false,
unstable_check = nocheck,
)
GC.gc()

#simulation
times = Vector{Float64}(undef,numberOfRuns)
Expand Down
20 changes: 9 additions & 11 deletions Lorenz_RK4/CPU_Julia/CPU_Lorenz_simple_julia.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DifferentialEquations, CPUTime, Statistics, SimpleDiffEq
using DifferentialEquations, CPUTime, Statistics, SimpleDiffEq, MuladdMacro

#settings
const unroll = 128
Expand All @@ -16,12 +16,11 @@ end

#ODE
function lorenz!(du, u, p, t)
@inbounds for j in 1:unroll
index = 3(j-1)+1
du[index] = 10.0 * (u[index+1] - u[index])
du[index+1] = p[j] * u[index] - u[index+1] - u[index] * u[index+2]
du[index+2] = u[index] * u[index+1] - 2.66666666 * u[index+2]
end
@muladd @inbounds for j in 1:unroll
du[j] = 10.0 * (u[j+unroll] - u[j])
du[j+unroll] = p[j] * u[j] - u[j+unroll] - u[j] * u[j+2*unroll]
du[j+2*unroll] = u[j] * u[j+unroll] - 2.66666666 * u[j+2*unroll]
end
end

#compile
Expand All @@ -35,9 +34,9 @@ solve(
save_start = false,
save_end = true,
adaptive = false,
dt = 0.01,
unstable_check = nocheck
dt = 0.01
)
GC.gc()

#simulation
times = Vector{Float64}(undef,numberOfRuns)
Expand All @@ -56,8 +55,7 @@ for runs in 1:numberOfRuns
save_start = false,
save_end = true,
adaptive = false,
dt = 0.01,
unstable_check = nocheck
dt = 0.01
)
end

Expand Down
7 changes: 4 additions & 3 deletions Lorenz_RK4/GPU_Julia/GPU_Lorenz_julia.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using DifferentialEquations, DiffEqGPU, CUDA, CPUTime, Statistics, SimpleDiffEq
using DifferentialEquations, DiffEqGPU, CUDA, CPUTime, Statistics, MuladdMacro

#settings
const numberOfParameters = 46080
const unroll = 2
const numberOfTrajectories = Int64(numberOfParameters/unroll)
const batchSize = numberOfTrajectories
const numberOfRuns = 2
const gpuID = 0 #Nvidia titan black device
const gpuID = 1 #Nvidia titan black device

#select device
CUDA.device!(gpuID)
Expand All @@ -29,7 +29,7 @@ end
parameterList = range(0.0,stop = 21.0,length=numberOfParameters)
p = zeros(unroll,1)
tspan = (0.0,10.0)
u0 = ones(unroll*3,1)
u0 = ones(unroll*3)

#parameter change function
#parameterChange = (prob,i,repeat) -> remake(prob,p=parameterList[i]) #it has slightly more allocations
Expand Down Expand Up @@ -59,6 +59,7 @@ solve(
dt = 0.01,
dense = false
)
GC.gc()

#simulation
times = Vector{Float64}(undef,numberOfRuns)
Expand Down
1 change: 1 addition & 0 deletions Lorenz_RK4/GPU_Julia/GPU_Lorenz_simple_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ solve(
dt = 0.01,
dense = false
)
GC.gc()

#simulation
times = Vector{Float64}(undef,numberOfRuns)
Expand Down

0 comments on commit fc55f01

Please sign in to comment.