# Environment variable for BLAS.set\_num\_threads default?

**URL:** https://discourse.julialang.org/t/environment-variable-for-blas-set-num-threads-default/67594
**Category:** Performance
**Tags:** blas, hpc, parallel
**Created:** [September 2, 2021, 6:26pm UTC](https://discourse.julialang.org/t/environment-variable-for-blas-set-num-threads-default/67594 "2021-09-02T18:26:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)
#### Post date: [September 2, 2021, 6:26pm UTC](https://discourse.julialang.org/t/environment-variable-for-blas-set-num-threads-default/67594/1 "2021-09-02T18:26:23Z")

</div>

Is there an environment variable that I can set in my `.bashrc` so I don’t have to manually prevent multiple BLAS threads (`BLAS.set_num_threads(1)`) in every program?

I never, ever want BLAS to run in multithreaded mode. It just drives me up the wall when numerical software uses multiple threads without me explicitly requesting it to (numpy has the same problem!).

- I don’t know what BLAS is trying to parallelize, but I do in fact find my code to run _faster_ (wallclock time) with a single BLAS thread, even without any apparent oversubscribing of CPUs (based on what I can see in `htop`)
- It interferes with my own parallelization: I will write code that uses `@threads` specifically to fill the cores of my machine, or run exactly as many single-threaded processes as I have cores. BLAS throwing in its own threads will then lead to oversubscription and slow everything down. This is even worse on an HPC cluster where I really need to hand-craft the number of processes/threads. If that gets screwed up, it eats into my budgeted project quotas.

I don’t suppose there’s any chance of Julia changing the default so that it never runs multiple BLAS threads unless I explicitly call `BLAS.set_num_threads`, is there?

---

<div class="post-metadata">

### Author: ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)
#### Post date: [September 2, 2021, 6:54pm UTC](https://discourse.julialang.org/t/environment-variable-for-blas-set-num-threads-default/67594/2 "2021-09-02T18:54:36Z")

</div>

I think this might work for openblas `export OPENBLAS_NUM_THREADS=4` this is on zsh, I’m not sure if the syntax is different for bash
