# Relation between BLAS.get\_num\_threads() and SLURM\_CPUS\_PER\_TASK

**URL:** https://discourse.julialang.org/t/relation-between-blas-get-num-threads-and-slurm-cpus-per-task/134199
**Category:** General Usage
**Tags:** blas, slurm
**Created:** [November 28, 2025, 7:03pm UTC](https://discourse.julialang.org/t/relation-between-blas-get-num-threads-and-slurm-cpus-per-task/134199 "2025-11-28T19:03:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mancolric](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mancolric/32/21799_2.png) [@mancolric](https://discourse.julialang.org/u/mancolric)
#### Post date: [November 28, 2025, 7:03pm UTC](https://discourse.julialang.org/t/relation-between-blas-get-num-threads-and-slurm-cpus-per-task/134199/1 "2025-11-28T19:03:36Z")

</div>

I am running the script `MWE.jl`

```julia-auto
using LinearAlgebra
display(BLAS.get_num_threads())

```

via SLURM command

```julia-auto
srun --nodes=1 --ntasks-per-node=1 --cpus-per-task=6 --mem=1G julia MWE.jl

```

As far as I know, for SLURM the CPUs are logical, so if I set `--cpus-per-task=6` I would expect that `BLAS.get_num_threads()` returns `6`. Instead, it returns `3`.

Why is that? Any help on this would be very much appreciated.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [November 29, 2025, 1:26am UTC](https://discourse.julialang.org/t/relation-between-blas-get-num-threads-and-slurm-cpus-per-task/134199/2 "2025-11-29T01:26:38Z")

</div>

It’s on purpose that BLAS uses half of the available threads on x86\_64 (to avoid potential hypethreading oversubscription), it’s also mentioned in [Julia 1.12 Highlights](https://julialang.org/blog/2025/10/julia-1.12-highlights/#threads_settings_respect_cpu_affinity). If you want to use a different number of OpenBLAS threads, set the env var `OPENBLAS_NUM_THREADS` appropriately.

---

<div class="post-metadata">

### Author: ![mancolric](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mancolric/32/21799_2.png) [@mancolric](https://discourse.julialang.org/u/mancolric)
#### Post date: [November 29, 2025, 11:58am UTC](https://discourse.julialang.org/t/relation-between-blas-get-num-threads-and-slurm-cpus-per-task/134199/3 "2025-11-29T11:58:36Z")

</div>

I have done so via `BLAS.set_num_threads` and the impact on performance is terrible. Is that normal? The architecture of the computer is single-threaded. Even if it was multi-threaded, for SLURM the CPU number refers to logical CPUs, so I should always be able to set the same number of threads than logical CPUs.
