I've just started to use Fortran and have a problem with using BLAS modules from (?) LAPACK in my program.
I'm working on Ubuntu 18.04, I've already installed (?) LAPACK and BLAS packages by command sudo apt-get install libblas-dev liblapack-dev
. I've also downloaded LAPACK from http://www.netlib.org/lapack/ website and install it according to this video.
My program is supposed to use blas_sparse
module, so I wrote something like that:
program example
use blas_sparse
implicit none
! some code ...
end program example
I'm trying to compile my code (example.F90
) using gfortran
with a following command:
gfortran example.F90 -llapack -lblas
like on this example video (1:11). However it does not work, the compiler returns:
example.F90:3:8:
use blas_sparse
1
Fatal Error: Can't open module file ‘blas_sparse.mod’ for reading at (1): No such file or directory
What's the problem in here? I see three potential reasons:
- The code is wrong.
- The command I'm using to compile is incorrect.
- LAPACK and BLAS are not really installed.
ad. 1.
Maybe I should add some module named blas_sparse
to my code? Moreover it just moves the problem to another place bacause I still need to import somehow procedures from BLAS. Unfortunately I don't really know how does use
command work, so I don't know what should I try to change.
ad. 2.
Maybe my compiler just don't know where -llapack
and -lblas
libraries are. I was trying trying to write it explicitly using
gfortran example.F90 -llapack -lblas -L/usr/local/lib
comand, because when installing LAPACK and BLAS I've created symbolic links to liblapack.a
and liblapack.a
(see ad. 3.). I don't know what are exactly -llapack
and -lblas
flags and it makes me difficult to check if the compiler 'can see' them.
ad. 3. What I did to install BLAS and LAPACK on my computer is:
- downloading LAPACK 3.8.0 from netlib.org/lapack website
- using following commands to extract the library and install the files on my computer
:
tar zxvf lapack-3.8.0.tar.gz
cd lapack-3.8.0/
cp make.inc.example make.inc
make blaslib
make lapacklib
sudo ln -s /home/Download/lapack-3.8.0/liblapack.a /usr/local/lib/liblapack.a
sudo ln -s /home/Download/lapack-3.8.0/librefblas.a /usr/local/lib/librefblas.a
And also installing it via apt-get
:
sudo apt-get install libblas-dev liblapack-dev
I'll be very thankful for any help to solve this problem.
EDIT:
I've actually found out that I should create those .mod
files using blas_sparse.f90
, blas_sparse_namedconstant.f90
and blas_sparse_proto.h
files from BLAST website. First two of them I've just added to my code as modules and the gfortan compiler creates proper (I hope) .mod
files. However the third one is written in C language, so I can't just put it into my code.
So now the question is how to bound the .h
file with my code. Do I need to create some makefile
or compile .h
file to create the .mod
file?
EDIT2:
It looks that just I didn't install sparse BLAS from the BLAST website. What I have should done was:
- downloading the library:
wget -P target/directory/ http://www.netlib.org/toms/818
- unpacking the file:
mv 818 818.gz
gunzip 818.gz
- removing first three lines and ading
.sh
extension:
tail -n +4 818 > 818.sh; rm 818
- installing the library:
bash 818.sh
# before doing the following step read the notes below
bash INSTALL # this file has been created by 818.sh
./TESTER/test_all # running test
What I also needed to do, in the last step, was to edit SOFTWARE/Makefile
and INSTALL
files and create TESTER/Makefile.GNU
file to use gfortran
as a compiler.
After all I copied blas_sparse.mod
file to the directory where my program is:
cp SOFTWARE/blas_sparse.mod blas_sparse.mod
and now I can compile the program using gfortran
compiler:
gfortran example.F90 -llapack -lblas