# Myid() does not work as expected in @everywhere

**URL:** <https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964>\
**Category:** New to Julia\
**Created:** [October 25, 2020, 3:12am UTC](https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964 "2020-10-25T03:12:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggarza](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggarza/32/2654_2.png) [@ggarza](https://discourse.julialang.org/u/ggarza)\
**Post date:** [October 25, 2020, 3:12am UTC](https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964/1 "2020-10-25T03:12:23Z")

</div>

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

```julia
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”.

 ![Screen Shot 2020-10-24 at 9.57.22 PM](https://global.discourse-cdn.com/julialang/original/3X/2/d/2dc662b46b06a92ef9d6e3a042676fffd71224d5.jpeg)

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?

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [October 25, 2020, 4:13am UTC](https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964/2 "2020-10-25T04:13:39Z")

</div>

~~That intepolation occurs first, “Process: $(myid())” in macro before calling serialization. That’s why you see 1 in all titles(check with `macroexpand`). `string("Process: ", myid())` prevents that, I think.~~

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [October 25, 2020, 4:15am UTC](https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964/3 "2020-10-25T04:15:52Z")

</div>

Confirming the above answer, this works for me:

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

```

EDIT:  
Referring to the below, I did not test the original version either.  
I also have titles 1-4 when running the original code.

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [October 25, 2020, 4:27am UTC](https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964/4 "2020-10-25T04:27:29Z")

</div>

Actually, my theory did not work out. I see different numbers in `title`s. Which version of julia are you using? Mine was `v1.5.2`.

---

<div class="post-metadata">

**Author:** ![ggarza](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggarza/32/2654_2.png) [@ggarza](https://discourse.julialang.org/u/ggarza)\
**Post date:** [October 25, 2020, 6:05am UTC](https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964/5 "2020-10-25T06:05:41Z")

</div>

I am running v1.5.2. I also have recently updated the `Plots` package.

The plots momentarily show the expected title before changing to “Process: 1”.

---

<div class="post-metadata">

**Author:** ![ggarza](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggarza/32/2654_2.png) [@ggarza](https://discourse.julialang.org/u/ggarza)\
**Post date:** [October 25, 2020, 6:16am UTC](https://discourse.julialang.org/t/myid-does-not-work-as-expected-in-everywhere/48964/6 "2020-10-25T06:16:17Z")

</div>

I used the modified code below and I still see the behavior in my original post.

```julia
using Distributed, Plots
addprocs(3)

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

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

@everywhere begin
    display(p)
end

```
