Skip to content

Commit

Permalink
Merge pull request #15 from baggepinnen/includeremote
Browse files Browse the repository at this point in the history
add include_remote
  • Loading branch information
ChrisRackauckas authored Aug 28, 2018
2 parents de38871 + 039297b commit 3038cb8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ passobj(3, 1, [:t, :u, :v])
@passobj 1 workers() Foo.foo
#Or
passobj(1, workers(), [:foo]; from_mod=Foo)

# Include a file on a path not available on a remote worker
include_remote(path, 2)
```

## Performance Note
Expand Down
20 changes: 19 additions & 1 deletion src/ParallelDataTransfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ module ParallelDataTransfer
end
end

"""
include_remote(path, [workers=workers()]; module=Main)
Includes a file which is not available on a remote worker by reading the file at the main node, parsing the text and evaluating the code on the remote workers listed in `workers`
"""
function include_remote(path, workers=workers(); mod=Main)
open(path) do f
text = read(f, String)
s = 1
while s <= length(text)
ex, s = Meta.parse(text, s)
for w in workers
@spawnat w Core.eval(mod, ex)
end
end
end
end


export sendtosimple, @sendto, sendto, getfrom, passobj,
@broadcast, @getfrom, @passobj, @defineat
@broadcast, @getfrom, @passobj, @defineat, include_remote
end # module
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,20 @@ mybar_3c1 = remotecall_fetch(()->Main.bar_vec[3].c,2)
@test mybar_3c1 == ones(3)
mybar_3c2 = @getfrom(2,bar_vec[3].c)
@test mybar_3c2 == ones(3)

path, io = mktemp() # Create temp file and store some definitions
println(io, "__f(x) = x")
println(io, "__g(x) = x")
close(io)

w = workers()
include_remote(path, w[1]) # Include file at remote
@test remotecall_fetch(()->@isdefined(__f), w[1])
@test remotecall_fetch(()->@isdefined(__g), w[1])
@test remotecall_fetch(()->!@isdefined(__f), w[2])
include_remote(path, w) # Include on all remotes
for w in w
@test remotecall_fetch(()->@isdefined(__f), w)
@test remotecall_fetch(()->@isdefined(__g), w)
end
rm(path)

0 comments on commit 3038cb8

Please sign in to comment.