Created
March 27, 2020 17:05
-
-
Save bstellato/c56a9458a56b3007835d15f4829bc47e to your computer and use it in GitHub Desktop.
Julia example of parallel execution
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
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