Is it possible to switch between BLAS libraries without recompiling program?
Sure, you have to have them installed, and on Ubuntu/Debian issue command
update-alternatives --config libblas.so.3
You'll get numbered list of alternatives and could switch between them easily
Link: https://wiki.debian.org/DebianScience/LinearAlgebraLibraries
Generalizing to multiple BLAS/LAPACK Libraries
Most scientific codes that rely on BLAS/LAPACK calls are implementation-agnostic. They usually require that the library is just linked as appropriate.
You've commented that the function prototypes are the same across implementations. This allows you to just have the prototypes in some myblas.h
and mylapack.h
headers then link whichever library you'd like to use.
It sounds like your primary concern is the implementation-specific stuff that you've utilized for MKL. The solution is to just not use this stuff. For example, the MKL types like MKL_INT
are not special. They are C datatypes that have been defined to allow generalize between LP32/LP64/ILP64 libraries which MKL provides. See this table.
Also, stuff like mkl_malloc
isn't special. It was introduced before the C standard had a thread-safe aligned alloc. In fact, that is all mkl_malloc
is. So instead, just use aligned_alloc
, or if you don't want to commit to C11 use _mm_malloc
, memalign
, etc...
On the other hand, MKL does provide some useful extensions to BLAS/LAPACK which aren't standardized (like transpositions, for example). However, this type of stuff is usually easy to implement with a special case BLAS/LAPACK call or easy enough to implement by yourself. MKL also has internal threading if you choose to use it, however, many BLAS/LAPACK libraries offer this.
what is high performance version of LAPACK and BLAS?
There are plenty of good implementations to pick from:
- Intel MKL is likely the best on Intel machines. It's not free though, so that may be a problem.
- According to their benchmark, OpenBLAS compares quite well with Intel MKL and is free
- Eigen is also an option and has a largish (albeit old) benchmark showing good performance on small matrices (though it's not technically a drop-in BLAS library)
- ATLAS, OSKI, POSKI are examples of auto-tuned kernels which will claim to work on many architectures
Generally, it is quite hard to pick one of these without benchmarking because:
- some implementations work better on different types of matrices. For example Eigen works better on matrices with small rank (100s)
- some are optimised for specific architectures (e.g. Intel's)
- in some cases the multithreading of the BLAS library may conflict with a multithreaded application (e.g. OpenBLAS)
- developer's benchmarks may tend to emphasise cases which work better on their implementation.
I would suggest pick one or two of these libraries that apply for your use case and benchmark them for your particular application on your particular (or similar) machine. This is quite easy to do even after compiling your code.
Related Topics
Why Does Poll Keep Returning Although There Is No Input
/Usr/Lib64/Libstdc++.So.6: Version 'Glibcxx_3.4.15' Not Found
How to Enable C++11 in Qt Creator
Read Unicode Utf-8 File into Wstring
Create a Directory If It Doesn't Exist
Why Shared_From_This Can't Be Used in Constructor from Technical Standpoint
C++ Compiling on Windows and Linux: Ifdef Switch
How to Evaluate Mathematical Expressions in C++
Are There Any Way to Link My Program with Wine-Compiled Part
Why Is Padding Added for Multiple Data Members of Structures and Not for Single Members
How Does the Omp Ordered Clause Work
What Default Promotions of Types Are There in the Variadic Arguments List
Convert Mat to Array/Vector in Opencv