# Distributed.jl: Group myid() by computing nodes?

**URL:** https://discourse.julialang.org/t/distributed-jl-group-myid-by-computing-nodes/100619
**Category:** Julia at Scale
**Tags:** distributed
**Created:** [June 20, 2023, 7:24pm UTC](https://discourse.julialang.org/t/distributed-jl-group-myid-by-computing-nodes/100619 "2023-06-20T19:24:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lmtzx9h4qqnt](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)
#### Post date: [June 20, 2023, 7:24pm UTC](https://discourse.julialang.org/t/distributed-jl-group-myid-by-computing-nodes/100619/1 "2023-06-20T19:24:24Z")

</div>

Using Distributed.jl, is there no built-in way to find out which workers are on the same shared-memory node? This post:

> [@@spawnat with SlurmClusterManager](https://discourse.julialang.org/t/spawnat-with-slurmclustermanager/78930/2):
>
> It seems the following works, though isn’t amazingly pretty. Thoughts appreciated. @everywhere begin function return\_id(x) return myid(), gethostname() end end nworkers = length(workers()) out = pmap(return\_id,1:nworkers) idlst = map(x-\>x[1],out) hostlist = map(x-\>x[2],out) df = DataFrame(id=idlst,host=hostlist) gp = groupby(df, :host) gvec = gp.groups nodeworkers = [] for i = 1:maximum(gvec) push!(nodeworkers,df.id[gvec.==i]) end Then you can manually build the SharedArra…

shows a manual implementation based on `gethostname()`, but I don’t know how robust that is? If there’s nothing built-in, maybe there’s already a package that helps with this?

My goal is to create one `SharedArray` per cluster node, which is accessible to all workers on that node, so I need to find out which machine each of the workers is running on.

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [June 21, 2023, 1:40am UTC](https://discourse.julialang.org/t/distributed-jl-group-myid-by-computing-nodes/100619/2 "2023-06-21T01:40:57Z")

</div>

Is this any help?

> [@How to get more info on w ∈ workers()](https://discourse.julialang.org/t/how-to-get-more-info-on-w-workers/34290/2):
>
> 1 i’m not sure about that but seems RemoteException type is for this purpose, maybe you can refer to julia manual here [Distributed Computing · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.RemoteException) 2 you can use Distributed.map\_pid\_wrkr function to map the pid to a Worker type, then you can lookup the hostname, such as Distributed.map\_pid\_wrkr[pid].config.host. config field is a WorkConfig type, and all field name can be obtained by using Distrbuted; fieldnames(WorkerConfig), that is (:io, :host, :port, :count, :exename, :exeflag…

---

<div class="post-metadata">

### Author: ![lmtzx9h4qqnt](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)
#### Post date: [June 21, 2023, 3:55pm UTC](https://discourse.julialang.org/t/distributed-jl-group-myid-by-computing-nodes/100619/3 "2023-06-21T15:55:20Z")

</div>

Well, since `Distributed.map_pid_wrkr` is not documented or exported, I’d be hesitant to rely on it. And it seems like the suggestion pretty much the equivalent of `pmap(_ -> gethostname(), procs())`?

---

<div class="post-metadata">

### Author: ![lmtzx9h4qqnt](https://avatars.discourse-cdn.com/v4/letter/l/74df32/32.png) [@lmtzx9h4qqnt](https://discourse.julialang.org/u/lmtzx9h4qqnt)
#### Post date: [June 23, 2023, 9:30am UTC](https://discourse.julialang.org/t/distributed-jl-group-myid-by-computing-nodes/100619/4 "2023-06-23T09:30:14Z")

</div>

I just noticed that Distributed does at least export `check_same_host(pids)` (no documentation, though), which also seems to be used by SharedArrays, and while that does allow one to check if the given processes are on the same node, it’d be pretty cumbersome and inefficient to use that to partition the processes by their nodes.
