Skip to content

Instantly share code, notes, and snippets.

@carlobaldassi
Created April 29, 2014 09:43
Show Gist options
  • Save carlobaldassi/11395493 to your computer and use it in GitHub Desktop.
Save carlobaldassi/11395493 to your computer and use it in GitHub Desktop.
Slowdown of a function executed remotely (Julia issue #6686)
module SlowRemoteExecution
type W
J::Vector{BitVector}
W(N::Int, K::Int) = new([randbool(N) for k=1:K])
end
function inner(ws::Vector{W}, X::Vector{BitVector})
r = 0
@time begin
for x in X, w in ws
J = w.J
s = 0
for j in J
s += dot(j, x) > 120
end
r += s > 50
end
end
return r
end
function inner_evenslower(ws::Vector{W}, X::Vector{BitVector})
r = 0
@time begin
Js = [w.J for w in ws]
for x in X, J in Js
s = 0
for j in J
s += dot(j, x) > 120
end
r += s > 50
end
end
return r
end
function inner_fastonremote(ws::Vector{W}, X::Vector{BitVector})
r = 0
@time begin
Jscs = [[j.chunks for j in w.J] for w in ws]
for x in X
xc = x.chunks
for Jcs in Jscs
s = 0
for jc in Jcs
d = 0
l = length(jc)
for i = 1:l
d += count_ones(jc[i] & xc[i])
end
s += d > 120
end
r += s > 50
end
end
end
return r
end
function outer(ws::Vector{W}, X::Vector{BitVector})
println("inner on local process")
println("----------------------")
@time x1 = remotecall_fetch(1, inner, ws, X)
println()
println("inner on worker")
println("---------------")
@time x2 = remotecall_fetch(2, inner, ws, X)
println()
println("inner_evenslower on local process")
println("---------------------------------")
@time x1s = remotecall_fetch(1, inner_evenslower, ws, X)
println()
println("inner_evenslower on worker")
println("--------------------------")
@time x2s = remotecall_fetch(2, inner_evenslower, ws, X)
println()
println("inner_fastonremote on local process")
println("-----------------------------------")
@time x1f = remotecall_fetch(1, inner_fastonremote, ws, X)
println()
println("inner_fastonremote on worker")
println("----------------------------")
@time x2f = remotecall_fetch(2, inner_fastonremote, ws, X)
println()
@assert x1 == x2 == x1s == x2s == x1f == x2f
end
function tst()
srand(1)
N = 500
K1 = 100
K2 = 200
M = 1_000
ws = [W(N, K1) for i = 1:K2]
X = [randbool(N) for i = 1:M]
outer(ws, X)
end
end
julia> SlowRemoteExecution.tst()
inner on local process
----------------------
elapsed time: 0.589470459 seconds (0 bytes allocated)
elapsed time: 0.589635775 seconds (424 bytes allocated)
inner on worker
---------------
From worker 2: elapsed time: 1.615534087 seconds (0 bytes allocated)
elapsed time: 2.12067934 seconds (38298756 bytes allocated)
inner_evenslower on local process
---------------------------------
elapsed time: 0.587374153 seconds (2048 bytes allocated)
elapsed time: 0.587548044 seconds (2488 bytes allocated)
inner_evenslower on worker
--------------------------
From worker 2: elapsed time: 2.265180296 seconds (2048 bytes allocated)
elapsed time: 2.810449319 seconds (38297416 bytes allocated)
inner_fastonremote on local process
-----------------------------------
elapsed time: 0.582856348 seconds (6581248 bytes allocated)
elapsed time: 0.583044048 seconds (6581688 bytes allocated)
inner_fastonremote on worker
----------------------------
From worker 2: elapsed time: 0.569549788 seconds (6581248 bytes allocated)
elapsed time: 1.108767959 seconds (38297624 bytes allocated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment