JuliaLang/julia — pull request #9181 by amitmurthy (2014-11-27 15:15:45+00:00)
Title: WIP/RFC: Testing optimizations to broadcast type of calls

Just trying out possibilities of optimizing calls which execute the same thunk on all workers.

With the regular master branch, and 8 workers, sending 10^7 Floats to all workers in parallel takes around 0.42 seconds:

```
function foo(n)
t=time()
a=fill(t, 10^n)
@time @sync begin
for p in workers()
@async @spawnat p global bar=a
end
end

#validate that the array has been sent over the network
for p in workers()
assert(remotecall_fetch(p, ()->length(bar)) == 10^n)
assert(remotecall_fetch(p, ()->bar[1]) == t)
end
end
```
```
julia> foo(7)
elapsed time: 0.428372318 seconds (1073780664 bytes allocated, 12.33% gc time)
```

With this PR, which implements a new macro `@spawnall`, the time is around 0.21 seconds
```
function foo(n)
t=time()
a=fill(t, 10^n)
@time @sync @spawnall global bar=a

#validate that the array has been sent over the network
for p in workers()
assert(remotecall_fetch(p, ()->length(bar)) == 10^n)
assert(remotecall_fetch(p, ()->bar[1]) == t)
end
end
```
```
julia> foo(7)
elapsed time: 0.218541978 seconds (134273124 bytes allocated, 7.87% gc time)
```

`@spawnall` serializes the request once and then sends the same buffer to all the workers.