Skip to content

Instantly share code, notes, and snippets.

@bstellato
Created March 27, 2020 17:05
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 bstellato/c56a9458a56b3007835d15f4829bc47e to your computer and use it in GitHub Desktop.
Save bstellato/c56a9458a56b3007835d15f4829bc47e to your computer and use it in GitHub Desktop.
Julia example of parallel execution
using ProgressMeter
using Distributed
addprocs(2)
@everywhere using LinearAlgebra
@everywhere function myfunc(theta)
for i in 1:100000
dot(theta, theta)
end
return Dict(["A" => norm(theta, 2), "B" => norm(theta, 1)])
end
# Create inputs
thetas = [rand(4) for _ in 1:10000]
time_serial = @elapsed results = @showprogress map(myfunc, thetas)
time_parallel = @elapsed results = @showprogress pmap(myfunc, thetas)
print("Time serial $(time_serial)\n")
print("Time parallel $(time_parallel)\n")
print("Speedup $(time_serial/time_parallel) x\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment