For example can I have Atlas, OpenBlas, MKL installed on my Ubuntu 14.04 at the same time and switch between them without recompiling Caffe?
3 Answers
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

- 18,636
- 3
- 38
- 64
-
Another question what if I build OpenBlas in ordinary way and with flag USE_OPENMP=1 ? Can I switch between them ? i.e. can I switch between library modifications/versions? – mrgloom Nov 24 '15 at 08:26
-
@mrgloom yes, but they should be different packages, providing the same alternative. Then `update-alternatives` will know about them – Severin Pappadeux Nov 24 '15 at 13:52
-
But how can I build them as several packages? For example if I build OpenBlas from source via `make` and then `make install PREFIX=your_installation_directory1` and then I compile with `make USE_OPENMP=1` and `make install PREFIX=your_installation_directory2`, can `update-alternatives` find my builds in this folders or how can I install two different builds of the same lib in ubuntu's default lib directory via `make install` ? – mrgloom Nov 24 '15 at 14:01
-
@mrgloom no, I'm talking about Debian/Ubuntu .deb packages. Best way is to download debian source package, alter it and rebuild. Check instructions here https://wiki.debian.org/BuildingAPackage – Severin Pappadeux Nov 24 '15 at 14:15
You could also do it without changing system wide settings, for example by adding the library you want to use to the LD_PRELOAD
or LD_LIBRARY_PATH
environment variables. The first library on this path will be the one used to resolve the symbols against.
For example, you could run with
LD_PRELOAD=/path/to/blas/lib.so ./my_executable_using_caffe
You can see that this approach would be extremely useful as part of a benchmarking script for different implementations since it doesn't affect the benchmarking environment itself. For example (in bash):
my_libraries=/path/to/blas1.so /path/to/blas2.so
for lib in $my_libraries
do
LD_PRELOAD=${lib} ./my_executable_using_caffe
done
This approach, based on dynamic linking, applies to any other shared library your program is compiled against.

- 3,797
- 2
- 21
- 36
Yes, you can. You just need to use dynamic library linking.
The libblas.so.3
is a soft linking to /etc/alternatives/libblas.so.3
Which in turn points to the BLAS
library implementation
For example if you installing Atlas
(sudo apt-get install libatlas3-base
):
/usr/lib/libblas.so.3 -> /etc/alternatives/libblas.so.3
/etc/alternatives/libblas.so.3 -> /usr/lib/atlas-base/atlas/libblas.so.3
while after installing Openblas
(sudo apt-get install libopenblas-base
):
/usr/lib/libblas.so.3 -> /etc/alternatives/libblas.so.3
/etc/alternatives/libblas.so.3 -> /usr/lib/openblas-base/libblas.so.3
Of course you can use your own soft link to your library builds.

- 3,482
- 16
- 34
-
`ldconfig -p` gives me `libblas.so.3gf (libc6,x86-64) => /usr/lib/libblas.so.3gf` and `libblas.so (libc6,x86-64) => /usr/lib/libblas.so` what is `libblas.so.3` can you elaborate on this? – mrgloom Nov 24 '15 at 13:25
-