Reputation: 37
I want to compute and add gradients to multiple arrays in parallel:
a = zeros(1,3); b = zeros(1,5)
a, b = @parallel (+) for i = 1:10
f(a,b)
end
Where f(a,b) returns gradients of a and b (these are arrays the same size as a and b, respectively). Obviously the above method doesn't work because tuples are immutable, but I can't think of a way to do this that doesn't involve combining a and b into a larger matrix. Any ideas?
Upvotes: 1
Views: 112
Reputation: 37
Not the most elegant, but this works:
function ta(t1,t2)
t1[1].+t2[1], t1[2].+t2[2]
end
a, b = @parallel (ta) for i = 1:10
f(a,b)
end
Upvotes: 1