Last active
August 29, 2015 14:10
-
-
Save amitmurthy/3206a4f61cf6cd6000ee to your computer and use it in GitHub Desktop.
ptest.jl
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
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