-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Single file multi-threading (read-only) #477
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #477 +/- ##
==========================================
- Coverage 86.06% 77.16% -8.90%
==========================================
Files 31 32 +1
Lines 4170 4704 +534
==========================================
+ Hits 3589 3630 +41
- Misses 581 1074 +493
☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi
thank you for your contribution!
At this stage, this PR will not do what we want it to do.
I like the new keyword argument and that you check for the file to be in read-only mode.
However, the JLDFile
object doesn not support parallel access.
To circumvent that, this PR must return a new JLDFile
instance every time you do jldopen(filename)
.
Possibly contrary to what I said earlier, maybe we don't need to keep track of OPEN_PARALLEL_FILES
. Currently it can't hold multiple file handles of the same file anyway. The only advantage would be to throw an error when a user first opens a parallel-read
file handle, then edits the file in regular mode and continues to read with the original file handle.
Makes sense, that shouldn't be too hard to remedy. |
Well the code definitely makes a new handle every time if |
|
Thank you for making the changes! That is fine - I don't think we can properly test this through CI. I'll have a final close look at the code and test it locally. Looking at the code now, I don't think I like the "OPEN_PARALLEL_FILES" list. I think we're better off without it. Also, you (probably accidentally) committed a manifest and a |
|
👍
I understand and appreciate the intention. I'd also support it if it were that simple.
Even harder to fix:
Since this is quite a bit of work (Would need to keep a full list of ALL open file handles and also check whether they are still open) I would prefer removing this safety check and add a warning in the docs instead.
That's fine. I can fix that in the end. |
Hi @ejmeitz, thanks for helping out! I relaxed the open conditions. (parallel and serial read is fine) |
Hi, I want to read a paraview_collection(mps_path) do pvd
@inbounds Threads.@threads for i in 1:itr
jldopen(jld2dir, "r"; parallel_read=true) do fid
# read data from jld2 file
time = fid["group$(i)/time"]
sig = fid["group$(i)/sig"]
...
# write data
VTU_cls = [MeshCell(VTKCellTypes.VTK_VERTEX, [i]) for i in 1:mp_num]
VTU_pts = Array{Float64}(mp_pos')
let vtk = vtk_grid(joinpath(anim_path, "iter_$(i)"), VTU_pts, VTU_cls)
vtk["stress"] = sig[:, [1, 2, 4]]'
pvd[time] = vtk
...
end
end
end
end output.mp4I noticed an issue in a multithreading scenario where some random time steps cause 'shaking'. I've checked the JLD2 file, and it is fine. Therefore, I suspect the issue might be caused by multithreading (it always works fine when multithreading is disabled). Is it because I am reading it the wrong way😅, or is it a bug in multithreading? |
@ZenanH |
I use this feature in my code and it works correctly, so I think JLD2 is fine. I don't really understand your code but there could be a race condition in there somewhere. Its hard to know if the issue is JLD2 or elsewhere. |
Thank you for your reply👍, the problem is on |
This PR aims to add support for multi-threaded read-only access to JLD2 files. I created a new global tracker
OPEN_PARALLEL_FILES
which keeps track of the files flagged as open for multi-threaded access. The flag for multi-threaded access was added to thejldopen
function asparallel_read
with a default of false. If the user changes this flag to true the program will check that the file is opened with in moder
and that it is not already present in theOPEN_FILES
list. If these checks are satisfiedjldopen
proceeds as normal. TheOPEN_FILES_LOCK
is not invoked whenparallel_read
is true.This is in reference to #403. Still need to add tests, but the existing tests pass locally.
Things I am unsure of: