@@ -24,13 +24,12 @@ export
2424# point-to-point
2525
2626function sendto(p:: Int , expr, data, mod:: Module = Main)
27- @sync @spawnat(p, Core. eval(mod, Expr(:(= ), expr, data)))
27+ @async @spawnat(p, Core. eval(mod, Expr(:(= ), expr, data)))
2828end
2929
3030function sendto(p:: Int , mod:: Module = Main; args... )
31- @sync for (nm, val) in args
32- @spawnat(p, Core. eval(mod, Expr(:(= ), nm, val)))
33- end
31+ data = Dict(nm => val for (nm, val) in args)
32+ @async @spawnat(p, Core. eval(mod, Expr(:(= ), :parallel_data, data)))
3433end
3534
3635function sendto(p:: Int , f:: Function , expr, mod:: Module = Main; args = ())
8079# broadcast
8180
8281function bcast(pids:: Array , expr, data, mod:: Module = Main)
83- for p in pids
82+ @sync for p in pids
8483 sendto(p, expr, data, mod)
8584 end
8685end
8786
8887function bcast(pids:: Array , mod:: Module = Main; args... )
89- for p in pids
88+ @sync for p in pids
9089 sendto(p, mod; args... )
9190 end
9291end
113112
114113function scatterto(pids:: Array , data:: Array , expr, mod:: Module = Main)
115114 if length(data) == length(pids)
116- for i in eachindex(pids)
115+ @sync for i in eachindex(pids)
117116 @inbounds sendto(pids[i], expr, data[i], mod)
118117 end
119118 else
135134# Gather
136135
137136function gather(pids:: Array , expr, mod:: Module = Main)
138- return [fetch(@spawnat(p, Core. eval(mod, expr))) for p in pids]
137+ # return [fetch(@spawnat(p, Core.eval(mod, expr))) for p in pids]
138+ results = Vector{Any}(undef, length(pids))
139+ @sync for (i, p) in enumerate(pids)
140+ @async results[i] = fetch(@spawnat(p, Core. eval(mod, expr)))
141+ end
142+ return results
139143end
140144
141145macro gather(pids, expr, mod:: Symbol = :Main)
0 commit comments