-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Create SharedArray from disk file #12560
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d849f60
SharedArrays: concretely type all fields, use LinearFast()
timholy 9c595c3
Re-export localindexes
timholy da942b6
Create a SharedArray from a disk file
timholy 11efb31
SharedArray: better error types, fix test on Windows
timholy 4fb455d
Harmonize error types in SharedArray constructor
timholy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1247,6 +1247,7 @@ export | |
# shared arrays | ||
sdata, | ||
indexpids, | ||
localindexes, | ||
|
||
# paths and file names | ||
abspath, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,18 @@ end | |
|
||
# TODO : Need a similar test of shmem cleanup for OSX | ||
|
||
# SharedArray tests | ||
##### SharedArray tests | ||
|
||
function check_pids_all(S::SharedArray) | ||
pidtested = falses(size(S)) | ||
for p in procs(S) | ||
idxes_in_p = remotecall_fetch(p, D -> parentindexes(D.loc_subarr_1d)[1], S) | ||
@test all(sdata(S)[idxes_in_p] .== p) | ||
pidtested[idxes_in_p] = true | ||
end | ||
@test all(pidtested) | ||
end | ||
|
||
d = Base.shmem_rand(1:100, dims) | ||
a = convert(Array, d) | ||
|
||
|
@@ -86,6 +97,66 @@ for p in procs(d) | |
@test d[idxl] == p | ||
end | ||
|
||
### SharedArrays from a file | ||
|
||
# Mapping an existing file | ||
fn = tempname() | ||
open(fn, "w") do io | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these should probably clean up after themselves when they're done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 13846e5 |
||
write(io, 1:30) | ||
end | ||
sz = (6,5) | ||
Atrue = reshape(1:30, sz) | ||
|
||
S = SharedArray(fn, Int, sz) | ||
@test S == Atrue | ||
@test length(procs(S)) > 1 | ||
@sync begin | ||
for p in procs(S) | ||
@async remotecall_wait(p, D->fill!(D.loc_subarr_1d, myid()), S) | ||
end | ||
end | ||
check_pids_all(S) | ||
|
||
filedata = similar(Atrue) | ||
open(fn, "r") do io | ||
read!(io, filedata) | ||
end | ||
@test filedata == sdata(S) | ||
|
||
# Error for write-only files | ||
@test_throws ErrorException SharedArray(fn, Int, sz, mode="w") | ||
|
||
# Error for file doesn't exist, but not allowed to create | ||
@test_throws SystemError SharedArray(tempname(), Int, sz, mode="r") | ||
|
||
# Creating a new file | ||
fn2 = tempname() | ||
S = SharedArray(fn2, Int, sz, init=D->D[localindexes(D)] = myid()) | ||
@test S == filedata | ||
filedata2 = similar(Atrue) | ||
open(fn2, "r") do io | ||
read!(io, filedata2) | ||
end | ||
@test filedata == filedata2 | ||
|
||
# Appending to a file | ||
fn3 = tempname() | ||
open(fn3, "w") do io | ||
write(io, ones(UInt8, 4)) | ||
end | ||
S = SharedArray(fn3, UInt8, sz, 4, mode="a+", init=D->D[localindexes(D)]=0x02) | ||
len = prod(sz)+4 | ||
@test filesize(fn3) == len | ||
filedata = Array(UInt8, len) | ||
open(fn3, "r") do io | ||
read!(io, filedata) | ||
end | ||
@test all(filedata[1:4] .== 0x01) | ||
@test all(filedata[5:end] .== 0x02) | ||
|
||
|
||
### Utility functions | ||
|
||
# reshape | ||
|
||
d = Base.shmem_fill(1.0, (10,10,10)) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can these be
ArgumentError
's? Also, using a personal pronoun in an error message is a bit weird.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.
Good points all round, will fix.