Skip to content

Instantly share code, notes, and snippets.

@amitmurthy
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitmurthy/3206a4f61cf6cd6000ee to your computer and use it in GitHub Desktop.
Save amitmurthy/3206a4f61cf6cd6000ee to your computer and use it in GitHub Desktop.
ptest.jl
const A = randn(1000, 1000);
const numx = 10_000;
const v = randn(1000, numx);
addprocs(4)
@sync begin
let A2=A, v2=v, numx2=numx
for p in workers()
@spawnat p global const A = A2;
@spawnat p global const numx = numx2;
@spawnat p global const v = v2;
end
end
end
@everywhere begin
do_stuff(r::UnitRange) = ([do_stuff(mm) for mm in r]; nothing)
function do_stuff(mm::Int64)
sum( A * v[:, mm] )
end
end
@time do_stuff(1:numx);
chunks = Base.splitrange(numx, nworkers())
for c in chunks
@time do_stuff(c);
end
@time @sync begin
for c in chunks # @parallel does the same
@spawn @time do_stuff(c)
end
end
@time @sync begin
for c in chunks
wait(@spawn @time do_stuff(c))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment