Are the LAPACK routines thread safe?

4k views Asked by At

I am a novice using the LAPACK routines, so I don't deeply know them, and I want to use them in parallelized loops (openmp).

I use Ubuntu 14.04LTS and have LAPACK installed using my package manager. The version installed is:

liblapack3    3.5.0-2ubuntu1     Library of linear algebra routines 3 - shared version

The associated BLAS library is:

libblas3    1.2.20110419-7

So, my first question is quite simple: can I use any subroutine or function of the LAPACK in a loop parallelized using OpenMP?. Id est, are they thread safe?.

Another questions is: Can I use any subroutine or function of the LAPACK in my pure subroutine?, id est, in a subroutine coded by me and defined as pure.

If the answer to these questions are "not with all LAPACK procedures but with some of them", then, can I do it with the following subroutines?:

  • dgetrs
  • dgetrf
  • dgetri
  • dgecon

And one last question: Do the LAPACK procedures use all my cores?, id est, are they already parallel?.

2

There are 2 answers

2
ztik On BEST ANSWER

The LAPACK library is expected to be thread safe. It does not support multiple threads, so it does not use (all) your systems cores. Actually there is a specific declaration that all LAPACK subroutines are thread-safe since v3.3.

On the other hand LAPACK is designed to use extensively BLAS library subroutines. The basic BLAS does not use any threads either. However there are several popular BLAS implementations (ATLAS, OpenBLAS, MKL) which have threaded versions of most BLAS subroutines. If your LAPACK library is using one of the above BLAS libraries then it is quite possible that their subroutines will start their own threads. Of course, in the above libraries, the user can control the number of threads used. You can consult their documentation to find out the way.

So you need to check which implementation of the BLAS library you use in order to have clear view of LAPACK's thread usage.

Regarding the usage inside pure functions, I wish to note that both BLAS and LAPACK print specific error messages on the screen (stdout or stderr). These messages usually related on false usage of the subroutine and not mathematical errors. For example if you try to invert a zero dimension matrix. If you can secure this then probably you can say it is pure.

2
Manuel Pena On

Correct me if I am wrong, but I think that, in general, LAPACK subroutines are not pure. Not only because they print out messages, but because they use to return the result stored in the input variable. That is, for example, if you try to invert a matrix, the subroutine is something like inv(A), where A is the input and output at the same time (intent (inout)) instead of having inv(A,B) where A is only in, and B is only out.

They cannot be pure because they modify their inputs.