Reputation: 72
In C++17, I want to use several OpenBLAS subroutines with a different number of threads for each. Is there any way to accomplish this?
In the past, I have used openblas_set_num_threads(); to set the number of threads for my OpenBLAS subroutines. While this works, it sets the openblas num threads globally, preventing each subroutines to use a different number of threads when running in parallel. Because of this, I use the same number of threads for all of my OpenBLAS subroutines so they can run in parallel.
Upvotes: 3
Views: 962
Reputation: 578
No way!! It seems that it is impossible so far. Based on their user manual:
If your application is already multi-threaded, it will conflict with OpenBLAS multi-threading
Actually, this feature is essential for most multithreaded libraries that want to use BLAS.
One easy option is to use MKL instead of OpenBLAS and use their mkl_set_num_threads_local
that can play nicely, and the developer has a good control over threads. Look here.
A harder option is to call single threaded OpenBLAS and you implement the multithreading yourself. This can work either with OpenBLAS and MKL but it is cumbersome and you will probably lose performance if you don't know what you are doing.
For this problem there is no difference if you use C++17, C++11, any other flavoer of C++ or C.
Upvotes: 1