Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are the LAPACK routines thread safe?

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?.

like image 338
Antonio Serrano Avatar asked Jun 17 '15 12:06

Antonio Serrano


People also ask

Is Blas thread safe?

Most BLAS implementations are thread safe, but some versions of OpenBLAS, for example, are not. This routine is a diagnostic helper function, which you will never need if you don't set nthreads>1 , and even then are unlikely to need.

What are thread safe libraries?

Software libraries can provide certain thread-safety guarantees. For example, concurrent reads might be guaranteed to be thread-safe, but concurrent writes might not be. Whether a program using such a library is thread-safe depends on whether it uses the library in a manner consistent with those guarantees.

What is a thread safe environment?

thread-safety or thread-safe code in Java refers to code which can safely be used or shared in concurrent or multi-threading environment and they will behave as expected. any code, class, or object which can behave differently from its contract on the concurrent environment is not thread-safe.


1 Answers

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.

like image 90
ztik Avatar answered Oct 17 '22 22:10

ztik