Last active
July 19, 2019 17:51
-
-
Save vlandau/78e0c411c39554701659a5cf8012bd85 to your computer and use it in GitHub Desktop.
Parallel distributed processing in Julia
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 Distributed | |
addprocs(2) | |
q = fill(rand(9), 3, 3) | |
@everywhere nrows = @eval size($q, 1) | |
@everywhere ncols = @eval size($q, 2) | |
for i in workers() | |
@spawnat i eval(:(a = fill(0, nrows, ncols))) | |
end | |
@everywhere function add_n!(a, n) | |
a[2,2] = a[2,2] .+ n | |
end | |
pmap(x -> add_n!(a, x), [1,1,1,1,1,1,1,1,1,1]) | |
function my_sum() | |
summed = fill(0, 3, 3) | |
for i in workers() | |
summed = summed .+ @fetchfrom i a | |
end | |
summed | |
end | |
my_sum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment