I have a problem where I would like to execute a number of statements in parallel that are independent of each other.
I have read plenty of examples that suggest this toy example should work:
function f1(x,y,z)
@sync @async begin
# these two statements can be computed independently
v1 = x+y;
v2 = y+z;
end
return v1*v2
end
However, it seems that the @sync part is not waiting for the results to be completed because I get the following error:
y1 = f1(1,2,3);
ERROR: LoadError: UndefVarError: v1 not defined
I have succeeded in making it work like this:
function f2(x,y,z)
v1 = @async x+y;
v2 = @async y+z;
return wait(v1)*wait(v2)
end
However, in many examples that I have seen, the wait statement seems to be unnecessary if one uses a @sync block.
I'm using Julia 0.6.2.
Any help would be highly appreciated.