How do you * get * the number of threads for BLAS operations in Julia?

The Julia blas library has a set_num_threads() function that sets threads for BLAS operations.

How to get the number of threads used by default or currently?

+5
source share
2 answers

If you have Julia associated with OpenBLAS, this will be the case if you use the Windows, Mac or generic Linux binaries from julialang.org, or if you create from the source code and do not set USE_SYSTEM_BLAS=1 , then you get the number of threads, used by OpenBLAS by calling ccall((:openblas_get_num_threads64_, Base.libblas_name), Cint, ()) . In the end, we assume that it will be a function of Julia.

+9
source

Module BLAS in Julia Base is a blas library wrapper that can be openblas , openblas , etc.

By default, OpenBLAS uses a single thread for small matrices and a multi-thread that you specify in variable variables for large matrices.

Set the number of threads with environment variables.

Examples:

export OPENBLAS_NUM_THREADS = 4 or

export GOTO_NUM_THREADS = 4 or

export OMP_NUM_THREADS = 4 Priorities: OPENBLAS_NUM_THREADS> GOTO_NUM_THREADS> OMP_NUM_THREADS.

If you compile this lib with USE_OPENMP = 1, you must set the OMP_NUM_THREADS> environment variable. OpenBLAS ignores OPENBLAS_NUM_THREADS and> GOTO_NUM_THREADS with USE_OPENMP = 1.

MKL can automatically adjust the number of threads for different matrix sizes.


You can use the global variable const dict ENV in Julia to get environment variables. But the number of threads you use will differ if you install it at run time or install it more than the kernels available on your computer.

If you use the Apple BLAS provided by vecLi , you can use ENV["VECLIB_MAXIMUM_THREADS"] to get the number of threads that you use, regardless of whether you set the number of threads with environment variables or set them at run time.

+2
source

All Articles