Skip to content

Commit

Permalink
Set forcing functions to nothing when restoring.
Browse files Browse the repository at this point in the history
Helps avoid #141 when forcing functions aren't used.
  • Loading branch information
ali-ramadhan committed Mar 19, 2019
1 parent 755000c commit fdaa3d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mutable struct Model
pressures::PressureFields
G::SourceTerms
Gp::SourceTerms
forcing::Forcing
forcing # ::Forcing # No type so we can set to nothing while checkpointing.
stepper_tmp::StepperTemporaryFields
poisson_solver # ::PoissonSolver or ::PoissonSolverGPU
clock::Clock
Expand Down
17 changes: 14 additions & 3 deletions src/output_writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ filename(fw::Checkpointer, iteration) = filename(fw, "model_checkpoint_", iterat
function write_output(model::Model, chk::Checkpointer)
filepath = joinpath(chk.dir, filename(chk, model.clock.iteration))

# Do not include the spectral solver parameters. We want to avoid serializing
forcing_functions = model.forcing

# Do not include forcing functions and FFT plans. We want to avoid serializing
# FFTW and CuFFT plans as serializing functions is not supported by JLD, and
# seems like a tricky business in general.
model.forcing = nothing
model.poisson_solver = nothing

println("WARNING: Forcing functions are not serialized!")

println("[Checkpointer] Serializing model to disk: $filepath")
f = JLD.jldopen(filepath, "w", compress=true)
JLD.@write f model
Expand All @@ -68,6 +73,9 @@ function write_output(model::Model, chk::Checkpointer)
model.poisson_solver = PoissonSolverGPU(grid, stepper_tmp.fCC1)
end

# Putting back in the forcing functions.
model.forcing = forcing_functions

return nothing
end

Expand All @@ -79,14 +87,17 @@ function restore_from_checkpoint(filepath)

println("Reconstructing FFT plans...")
metadata, grid, stepper_tmp = model.metadata, model.grid, model.stepper_tmp
if metadata.arch == :cpu
if metadata.arch == :CPU
stepper_tmp.fCC1.data .= rand(metadata.float_type, grid.Nx, grid.Ny, grid.Nz)
model.poisson_solver = PoissonSolver(grid, stepper_tmp.fCC1, FFTW.PATIENT)
elseif metadata.arch == :gpu
elseif metadata.arch == :GPU
stepper_tmp.fCC1.data .= CuArray{Complex{Float64}}(rand(metadata.float_type, grid.Nx, grid.Ny, grid.Nz))
model.poisson_solver = PoissonSolverGPU(grid, stepper_tmp.fCC1)
end

model.forcing = Forcing(nothing, nothing, nothing, nothing, nothing)
println("WARNING: Forcing functions have been set to nothing!")

return model
end

Expand Down

0 comments on commit fdaa3d7

Please sign in to comment.