# Mapping Hwloc logical index to OS index

**URL:** <https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377>\
**Category:** Julia at Scale\
**Created:** [April 12, 2022, 10:46am UTC](https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377 "2022-04-12T10:46:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [April 12, 2022, 10:46am UTC](https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377/1 "2022-04-12T10:46:35Z")

</div>

The docs for Hwloc library state that the logical indices of Processor units used by Hwloc are not the same as the indices used by OS.

- How does one map Hwloc logical indices to OS indices?
- Is this functionality exposed in Hwloc.jl wrapper?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [April 12, 2022, 11:19am UTC](https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377/2 "2022-04-12T11:19:11Z")

</div>

> [@Gregstrq](#):
>
> How does one map Hwloc logical indices to OS indices?

AFAIU, that can be system / OS dependent. So there is no unique answer here.

> [@Gregstrq](#):
>
> Is this functionality exposed in Hwloc.jl wrapper?

No, because of the above.

In ThreadPinning.jl (which only works on Linux) I parse the output of `lscpu --all --extended` to get the OS indices.

---

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [April 12, 2022, 11:30am UTC](https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377/3 "2022-04-12T11:30:43Z")

</div>

> [@carstenbauer](#):
>
> AFAIU, that can be system / OS dependent. So there is no unique answer here.

Actually, it seems that Hwloc objects store both logical index assigned by Hwloc and an index assigned by os. Look at the picture at the bottom of [this page](https://www.open-mpi.org/projects/hwloc/doc/v1.11.13/a00279.php).

---

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [April 12, 2022, 1:41pm UTC](https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377/4 "2022-04-12T13:41:05Z")

</div>

Ok. Now I am really confused.

I looked at [this line in the source code of Hwloc.jl](https://github.com/JuliaParallel/Hwloc.jl/blob/549a5109da1c8ba7b2478f4dcf9855cf49438318/src/highlevel_api.jl#L21).  
What I see, is that all hwloc objects indeed have the field `os_index`. It is actually used to print the topology.  
It seems, that I can get the os indices of all processing units by doing

```julia
using Hwloc
collectobjects(:PU) .|> x->getproperty(x, :os_index)

```

@carstenbauer Do you want to say, that the field `os_index` does not actually correspond to the index used by OS?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [April 12, 2022, 3:03pm UTC](https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377/5 "2022-04-12T15:03:17Z")

</div>

I believe to remember that I had a case where hwloc and lscpu didn’t agree but maybe I’m hallucinating. Sorry that I can’t clarify. Given that the field is called `os_index` I would think (and hope) that it’s correct and what you’re looking for.

---

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [April 12, 2022, 3:12pm UTC](https://discourse.julialang.org/t/mapping-hwloc-logical-index-to-os-index/79377/6 "2022-04-12T15:12:29Z")

</div>

> [@carstenbauer](#):
>
> I had a case where hwloc and lscpu didn’t agree

Could it be that you compared an hwloc `logical_index` with the output of lscpu?

If you really observed a discrepancy, may be it is a good idea to file an issue with [the hwloc library](https://github.com/open-mpi/hwloc). Yeah, if only we had time for everything.
