Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

Myid() does not work as expected in @everywhere

$
0
0

I’m running the following code in Visual Studio Code:

using Distributed, Plots
addprocs(3)

@everywhere begin
    using Plots
    x = [0, 300]
    y = [0, 300]
    p = scatter(x, y)
    title!(p, "Process: $(myid())")
    display(p)
end


@distributed for i = 1:300
    # title!(p, "Process: $(myid())")
    append!(p, (i, i))
    display(p)
end

My expectation is that this will show four plots, one for each process and that the plots will have different titles corresponding to the process id of each plot as determined by myid(). However, instead I get that the four plots each have the same title: “Process: 1”.

If I move the line with title! to the @distributed for loop, then I get the expected behavior. But why is it working this way?

6 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles