Skip to content

Commit

Permalink
Bug fix in JLD2 to avoid MmapIO failed error
Browse files Browse the repository at this point in the history
  • Loading branch information
zjwegert committed May 24, 2024
1 parent 921f62f commit df59677
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ LocalPreferences.toml
GridapTopOpt.so

# Ensure never to write results to git
results/*
results/*
tmp/*
2 changes: 1 addition & 1 deletion src/GridapTopOpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using GridapSolvers
using GridapSolvers.LinearSolvers, GridapSolvers.NonlinearSolvers, GridapSolvers.BlockSolvers
using GridapSolvers.SolverInterfaces: SolverVerboseLevel, SOLVER_VERBOSE_NONE, SOLVER_VERBOSE_LOW, SOLVER_VERBOSE_HIGH

using JLD2: save_object, load_object
using JLD2: save_object, load_object, jldsave

import Base: +

Expand Down
4 changes: 2 additions & 2 deletions src/Io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ end
"""
psave(filename::AbstractString, x)
Save a partitioned object `x` to a directory `dir` as
Save a partitioned object `x` to a directory `dir` as
a set of JLD2 files corresponding to each part.
"""
function psave(dir::AbstractString, x)
Expand All @@ -46,7 +46,7 @@ function psave(dir::AbstractString, x)
arr = to_local_storage(x)
map(ranks,arr) do id, arr
filename = joinpath(dir,basename(dir)*"_$id.jdl2")
save_object(filename,arr)
jldsave(filename, IOStream; arr)
end
end

Expand Down
28 changes: 28 additions & 0 deletions test/mpi/JLD2SaveLoadMPI.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module JLD2SaveLoadMPI
using Test

using Gridap, Gridap.MultiField, GridapDistributed, GridapPETSc, GridapSolvers,
PartitionedArrays, GridapTopOpt, SparseMatricesCSR

function main(distribute,mesh_partition)
ranks = distribute(LinearIndices((prod(mesh_partition),)))
path = joinpath("tmp","test")
i_am_main(ranks) && mkpath(path)
# setup
model = CartesianDiscreteModel(ranks,mesh_partition,(0,1,0,1),(20,20))
V_φ = TestFESpace(model,ReferenceFE(lagrangian,Float64,1))
φh = interpolate(initial_lsf(4,0.2),V_φ)

psave(path,get_free_dof_values(φh))
x = pload(path,ranks)
@assert x == get_free_dof_values(φh)
pload!(path,x)
@assert x == get_free_dof_values(φh)
true
end

with_mpi() do distribute
@test main(distribute,(2,2))
end

end # module
22 changes: 22 additions & 0 deletions test/seq/JLD2SaveLoad.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module JLD2SaveLoad
using Test

using Gridap, GridapTopOpt

function main()
path = joinpath(mktempdir(), "test.jld2")
# setup
model = CartesianDiscreteModel((0,1,0,1),(20,20))
V_φ = TestFESpace(model,ReferenceFE(lagrangian,Float64,1))
φh = interpolate(initial_lsf(4,0.2),V_φ)

save(path,get_free_dof_values(φh))
x = load(path)
@test x == get_free_dof_values(φh)
load!(path,x)
@test x == get_free_dof_values(φh)
end

main()

end # module
1 change: 1 addition & 0 deletions test/seq/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ using Test
@time @testset "Inverse Homogenisation - ALM" begin include("InverseHomogenisationALMTests.jl") end
@time @testset "Inverter - HPM" begin include("InverterHPMTests.jl") end
@time @testset "PZMultiFieldRepeatingState - ALM" begin include("PZMultiFieldRepeatingStateTests.jl") end
@time @testset "JLD2SaveLoad" begin include("JLD2SaveLoad.jl") end

end # module

0 comments on commit df59677

Please sign in to comment.