Environment variable for BLAS.set_num_threads default?

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?

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

1 Like