Fazeleh
Fazeleh

Reputation: 1128

use different arrays for each workers instead of SharedArrays in Julia

I have a function like this:

@everywhere function bellman_operator!(rbc::RBC)

    ...
    @sync @parallel for i = 1:m
        ....
        for j = 1:n
            v_max = -1000.0
            ...
                for l = Next : n
                    ......
                    if v > vmax
                        vmax = v
                        Next = l
                    else
                        break 
                    end

                end
                f_v[j, i] = vmax
                f_p[j, i] = k
          end
    end  

end

f_v and f_p are sharedArrays, I want to give different arrays for result of each workers, I saw some sample but I can't fix it.How can I use arrays for result of each workers and finally combine the results instead of using SharedArrays?

Upvotes: 0

Views: 51

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69829

Is this what you want?

Example 1. Combining results using +:

a = @parallel (+) for i in 1:1000
    rand(10, 10)
end

Example 2. Just collecting the results without combining them:

x = Future[]
for i in 1:1000
    push!(x, @spawn rand(10,10))
end
y = fetch.(x)

Upvotes: 1

Related Questions