Dear Colleagues, for anyone interested in linking the Julia language with some version of OpenBLAS compiled and installed separately from Julia, consider following the tutorial below. I still can not explain why consider just installing Julia and letting Julia automatically install OpenBLAS is 3 to 4 times slower on my machine. However, as I prefer to consider a separate installation of OpenBLAS, since I use it for several other applications, my problem is solved.
Instructions for compiling Julia language with OpenBLAS (GNU/Linux)
IMPORTANT : Be sure to remove all versions of BLAS , LAPACK and OpenBLAS installed in /usr/lib
and /usr/lib64
.
DEPENDENCES:
- git
- make
- cmake
- gcc
- gcc-fortran
- patch
Important: I’ll be at all times assuming that the project Julia has been cloned into the directory $HOME/Downloads
. Also, I will consider the /opt
directory as the installation directory for the OpenBLAS library and of the Julia language. You can choose a directory of your choice.
Compiling OpenBLAS
Initially download the Julia and OpenBLAS (Open Optimized BLAS Library) source codes in OpenBLAS. In the file directory, perform the following steps.
Note:
- Simply invoking make (or gmake on BSD) will detect the CPU automatically. To set a specific target CPU, use
make TARGET=xxx
, e.g. make TARGET=HASWELL
. The full target list is in the file TargetList.txt.
- This will make the compilation run faster using all the features of your CPU. To know the number of cores, do:
nproc
. The default installation directory is /opt/OpenBLAS
.
cd $HOME/Downloads
tar -zxvf OpenBLAS*
cd OpenBLAs*
make -j $(nproc)
sudo make install PREFIX=/opt/OpenBLAS
or
cd $HOME/Downloads
git clone https://github.com/xianyi/OpenBLAS.git
cd OpenBLAS*
git checkout v0.3.5
make -j $(nproc)
sudo make install PREFIX=/opt/OpenBLAS
Modifying the directory /opt/OpenBLAS (Soft Links)
In order for the Julia language compilation to proceed correctly with the link to the OpenBLASlibrary installed in the /opt/
directory, we have to create some soft links. The /opt/OpenBLAS/lib
directory and symbolic links should be of the following form:
Some of the soft links had already been created with the library installation OpenBLAS. To create the remaining symbolic links, do the following:
cd /opt/OpenBLAS/lib
sudo ln -sf libopenblas_haswellp-r0.3.5.so libblas.so
sudo ln -sf libopenblas_haswellp-r0.3.5.so libcblas.so
sudo ln -sf libopenblas_haswellp-r0.3.5.so liblapack.so
sudo cp -a lib* /usr/lib64
sudo cp -a lib* /usr/lib
Note:
1 - Make sure that there is no installed version of blas, lapack and OpenBLAS in /usr
. The command cp -a lib *
will copy the compiled OpenBLAS library files along with the symbolic links created so they can be used throughout the system.
2 - Note that the libopenblas_haswellp-r0.3.5.so file may have a different name on your machine because of the version of OpenBLAS and computer architecture. Usually it has a name in the form libopenblas_xxx. If this is the case, make the necessary change in file name.
Cloning the Julia Project
Initially do the Julia project clone on GitHub. That way, with git installed and configured, do:
cd $HOME/Downloads && git clone git://github.com/JuliaLang/julia.git
cd julia
After downloading all the project files Julia cloned to the computer, go to the version you want to compile, for example the version v1.1.0. To know the versions, list all the tags of the language versions of the cloned project (git tag -l
).
git checkout v1.1.0
Creating the Make.user
file
Subsequently, have the OpenBLAS library in the /opt/OpenBLAS/lib/
directory be added to the environment variable LD_LIBRARY_PATH
. In Linux, the LD_LIBRARY_PATH
environment variable is a set of colon-separated directories where libraries should be searched first, before the default set of directories. This will cause the Julia compilation to consider the OpenBLAS library of the /opt/OpenBLAS/lib/
. In the cloned directory, create the Make.user
file with the following content:
cd $HOME/Downloads/julia
USE_SYSTEM_XXX=1
MARCH=native
LDFLAGS=-Wl,-rpath,/usr/lib64
LDFLAGS+=-Wl,-rpath,/usr/lib
LDFLAGS+=-Wl,-rpath,/opt/OpenBLAS/lib
OPENBLAS_DYNAMIC_ARCH=0
USE_SYSTEM_BLAS=1
USE_SYSTEM_LAPACK=1
or
cd $HOME/Downloads/julia
echo "USE_SYSTEM_XXX=1
MARCH=native
LDFLAGS=-Wl,-rpath,/usr/lib64
LDFLAGS+=-Wl,-rpath,/usr/lib
LDFLAGS+=-Wl,-rpath,/opt/OpenBLAS/lib
OPENBLAS_DYNAMIC_ARCH=0
USE_SYSTEM_BLAS=1
USE_SYSTEM_LAPACK=1" > Make.user
Note: Other paths of libraries of interest can be added to the Make.user
file by doing LDFLAGS+=-Wl,-rpath,/path/of/library
.
Now, under the cloned directory of Julia, under the version of interest, compile the language doing:
cd $HOME/Downloads/julia
make -j $(nproc)
echo "prefix=/opt/julia" >> Make.user
cd /opt
sudo mkdir julia
cd $HOME/Downloads/julia
sudo make install
sudo ln -sf /opt/julia/bin/julia /usr/bin
julia
Note: In my tests, the procedure of compiling OpenBLAS separately and later compiling the Julia language provided greater computational efficiency.
This tutorial has been deposited in: https://github.com/prdm0/compiling_julia/blob/master/README.md.
Best regards.