Hi everyone,
I would like to run two functions at the same time. A very basic example is
addprocs(3)
@everywhere begin
function f()
sleep(1)
println("function f() is working")
return [1 2]
end
function g()
sleep(2)
println("function g() is working")
return [3 4 5]
end
end
Then, I can perfect run them using remotecall_fetch
a,b = 0,0
@time begin
a = remotecall_fetch(f,2)
b = remotecall_fetch(g,3)
end
println(a)
println(b)
The result is:
From worker 2: function f() is working
From worker 3: function g() is working
3.005970 seconds (957 allocations: 51.297 KiB)
[1 2]
[3 4 5]
I would like to use @async
, but the end result is wrong:
a,b = 0,0
@time @sync begin
@async a = remotecall_fetch(f,2)
@async b = remotecall_fetch(g,3)
end
println(a)
println(b)
From worker 2: function f() is working
From worker 3: function g() is working
2.031729 seconds (1.40 k allocations: 88.197 KiB)
0
0
what am I missing ?