blas_thread Module

the thread-count setter/getter of the linked BLAS library (OpenBLAS, MKL, BLIS) at run time via dlsym(). Use it to switch BLAS to single-threaded mode around OpenMP-parallel regions that issue many small BLAS calls, where a BLAS-internal thread pool (e.g. pthread builds of OpenBLAS) oversubscribes the machine and serializes on its pool lock.

If the BLAS library is not recognized, blas_thread_count returns -1 and blas_thread_set is a no-op, so the calls are always safe:

nSaved = blas_thread_count() call blas_thread_set(1_c_int64_t) !$omp parallel ... !$omp end parallel call blas_thread_set(nSaved) ! no-op if nSaved == -1