You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation of multithreading/thread safety capabilities are currently incomplete.
Case in point, I want to build a Fortran library that makes some BLAS/LAPACK calls, then use this library in a C++ program, that uses C++11 parallelism to call a subrutine from said Fortran library in parallel. If I want the BLAS/LAPACK operations to run single threaded, do I still need to set USE_OPENMP = 1 and NUM_PARALLEL = N, or is it irrelevant if I set USE_THREAD = 0?
What if I wanted to use OpenMP in my C++ code, instead of C++11 parallelism?
So a decision tree of possible use cases or a flowchart would be nice to help choose the proper values for USE_THREAD USE_OPENMP NUM_THREADS NUM_PARALLEL and when to use FCOMMON_OPT = -frecursive
IMO, the number of threading related build time variables, and their relationships to each other are getting more and more numerous, without proper documentation.
No need to dramatize this, the only recent addition is NUM_PARALLEL which is more of an experimental workaround to allow several instances of OpenBLAS, invoked from different parts of an OpenMP main program, to coexist without trashing thread memory. So you want to set/change this only if you build with USE_OPENMP=1, if at all. When you build with USE_THREAD=0 for a single-threaded OpenBLAS, there is no need to set USE_OPENMP=1 - in fact you will get a warning message from Makefile.system if you try. (It may still be necessary to set NUM_THREADS to a number greater than 1 in some cases just to ensure OpenBLAS allocates a sufficiently sized memory buffer internally).
When you want to use OpenMP in your C++ code and want a parallel OpenBLAS, it is mandatory to build OpenBLAS with USE_OPENMP=1 to avoid locking conflicts.
FCOMMON_OPT=-frecursive is a workaround for a thread safety problem inherited from netlib LAPACK, see http://icl.cs.utk.edu/lapack-forum/viewtopic.php?t=1930, so you would normally want to enable this in multithreaded builds.
OK, thanks for the clarification. I am probably going to expand the wiki with these threading recommendations.
I have two more questions though:
Is there a performance difference between using a single threaded build, and a parallel build set to 1 thread at runtime?
(might be a silly question) If the calling program uses OpenMP and parallel OpenBLAS, but all calls into OpenBLAS are outside the parallel region, is it necessary to set USE_OPENMP=1 at build time?
There should be no performance difference with 0.3.1, earlier versions would have some additional overhead from thread memory initialization on startup. About your other question I am not sure, but probably it is safer to build with USE_OPENMP=1 as well.
Activity
[-]Thread safety documentation[/-][+]Threading and thread safety documentation[/+]martin-frbg commentedon Jul 19, 2018
No need to dramatize this, the only recent addition is NUM_PARALLEL which is more of an experimental workaround to allow several instances of OpenBLAS, invoked from different parts of an OpenMP main program, to coexist without trashing thread memory. So you want to set/change this only if you build with USE_OPENMP=1, if at all. When you build with USE_THREAD=0 for a single-threaded OpenBLAS, there is no need to set USE_OPENMP=1 - in fact you will get a warning message from Makefile.system if you try. (It may still be necessary to set NUM_THREADS to a number greater than 1 in some cases just to ensure OpenBLAS allocates a sufficiently sized memory buffer internally).
When you want to use OpenMP in your C++ code and want a parallel OpenBLAS, it is mandatory to build OpenBLAS with USE_OPENMP=1 to avoid locking conflicts.
FCOMMON_OPT=-frecursive is a workaround for a thread safety problem inherited from netlib LAPACK, see http://icl.cs.utk.edu/lapack-forum/viewtopic.php?t=1930, so you would normally want to enable this in multithreaded builds.
TiborGY commentedon Jul 20, 2018
OK, thanks for the clarification. I am probably going to expand the wiki with these threading recommendations.
I have two more questions though:
USE_OPENMP=1at build time?martin-frbg commentedon Jul 21, 2018
There should be no performance difference with 0.3.1, earlier versions would have some additional overhead from thread memory initialization on startup. About your other question I am not sure, but probably it is safer to build with USE_OPENMP=1 as well.