Last active
August 29, 2015 14:07
-
-
Save sbchisholm/0749dc9434f9a00490a0 to your computer and use it in GitHub Desktop.
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
module RemoteHelpers | |
using Base: sync_add | |
function remote_call_from_module(w, expression::Expr) | |
call_expr = :(remotecall($w, eval, Main, $(Expr(:quote, expression)))) | |
eval(Main, call_expr) | |
end | |
remote_eval(w, expression::Expr) = remote_call_from_module(w, expression) | |
function remote_eval(expression::Expr) | |
@sync begin | |
for w in workers() | |
sync_add(remote_eval(w,expression)) | |
end | |
end | |
end | |
end | |
# Below is an example of some of the operations that are being done. The example | |
# may not make complete sense but these are the basic operations: | |
# Create/Update a variable on each worker | |
# Run a loop on each worker which should replace a row of an existing matrix | |
using RemoteHelpers | |
using Base: sync_add | |
a = addprocs(4) | |
# This type of call has a memory leak on the workers. | |
for j = 1:250 | |
c = rand(50, 5000) | |
@sync begin | |
for i in a | |
sync_add(remote_eval(i, :(begin | |
n = 50 | |
b = 5000 | |
c = $c | |
result = zeros(n, b) | |
for j = 1:n | |
result[j, :] = rand(1, b) | |
end | |
end))) | |
end | |
end | |
end | |
rmprocs(a) | |
## But calling doing this does not result in a memory leak | |
a = addprocs(4) | |
for j = 1:250 | |
c = rand(50, 5000) | |
@sync begin | |
for i in a | |
sync_add(remote_eval(i, quote | |
n = 50 | |
b = 5000 | |
c = $c | |
result = zeros(n, b) | |
end)) | |
end | |
end | |
@sync remote_eval(quote | |
for j = 1:n | |
result[j, :] = rand(1, b) | |
end | |
end) | |
end # module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment